I'm trying to keep things as simple as possible.
Obviously, for any particular method I know the
parameters. Suppose I have a method like this;
public int Compute( int a, int b )
{
try {
return a * b;
} catch ( Exception ex ) {
Log.Write( ex, string.Format( "a={0}, b={1}", a,
b ) );
throw;
}
}
When an exception is thrown I log the exception and the
parameters to the method, ignoring the fact that (in
general) member variables may have contributed to the
exception.
Now suppose that the method is changed, but that the lazy
programmer forgets to update the logging statement
public int Compute( int a, int b, int c )
{
try {
return a * b * c;
} catch ( Exception ex ) {
Log.Write( ex, string.Format( "a={0}, b={1}", a,
b ) );
throw;
}
}
If we look at the logs, we might be confused as to why
the exception is being thrown. I'm trying to make error
logging simpler (for the consumer).
Thanks for your concern.
-----Original Message-----
If you really want to do this, you received some good
answers already.
I feel that this is bad architectural practice because
it obscures what isreally happening in the error handlers, and it adds
unnecessary complexityto the code base.
The axim "Just because you can do something doesn't mean
you should do it"applies farily often to reflection - keep it simple.
Eric
"Brad Quinn" <br********@yahoo.com> wrote in message
news:01****************************@phx.gbl... Is there a way to get the values of the paramaters to a
method programatically?
I know that I can use reflection to find out the
parameter names and types, etc., but I want to know the
values of those parameters too.
I'm trying to write a generic error handler. I wan't
to be able to log the values that caused the error,
without the user of the class having to specify the
values 'cause they're lazy ;)
Thanks,
Brad
.