tags:

views:

900

answers:

2

I'm writing an error handling module for a fairly complex system architected into layers. Sometimes our data layer throws obscure exceptions.

It would be really handy to log out the values of the parameters of the method that threw the exception.

I can reflect on the TargetSite property of the exception to find the method's parameter types and names, but I don't seem to be able to get the values... am I missing something?


Dupe

http://stackoverflow.com/questions/157911/in-a-net-exception-how-to-get-a-stacktrace-with-argument-values

A: 

In short ... no. See this question on capturing method state for some reasons.

Rob Walker
+1  A: 

The built in framework ArgumentOutOfRangeException (which you should throw in a method if the incoming parameters are... out of range... has private field and public property for the method parameter that caused the error... When you create this exception, you pass the parameter value in the ctor...

throw new ArgumentOutOfRangeException(string parameterName, 
           object actualValue, string message);

For other exceptions, if you catch the exception in the method where it is thrown, and wrap it in a custom exception of your own, that has additional fields and properties for those method parameters

Charles Bretana