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
In a .net Exception how to get a stacktrace with argument values
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
In short ... no. See this question on capturing method state for some reasons.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With