views:

64

answers:

3

I honestly don't throw exceptions often. I catch them even less, ironically. I currently work in shop where we let them bubble up to avicode. For whatever reason, however, avicode isn't configured to capture some of the critical bits I need when these exceptions come bouncing back to my attention. Specifically, I'd like to see the parameter values and the class’s field data at the time of the exception.

I’d guess with the large suite of .Net services that I could create a static method to crawl up the stack, gather these bits and store them in a string that I could stick in my exception message. I really don't are how long such a method would take to execute as performance is no longer a concern when I hit one of these scenarios.

If it's possible, I'm sure someone has done it. If that's the case, I'm having a hard time finding it. I think any search containing "exception" brings back too many resutls.

Anyway, can this be done? If so, some examples or links would be great.

Thanks in advance for your time, Robert

A: 

I am prepared to be wrong about this, but I do not think it is possible to extract parameter values by walking the stack. You certainly cannot do this with the StackTrace and StackFrame classes.

From a security perspective this makes sense because sensitive information could be embedded in the stack that unauthorized code should not have access to.

If the current stack frame does not catch the exception and record its parameter values into an Exception instance before rethrowing then I am afraid you are going to be out of luck.

Brian Gideon
A: 

I think you can use the CLR Debugging API to get out some more information than just the stacktrace, but I don't think it's easy. http://msdn.microsoft.com/en-us/library/bb384548.aspx

ho1
A: 

Not sure if this is exactly what you are looking for, but as a consultant for AVIcode I can assure that it is a simple configuration change to collect parameters and member variables by namespace, class or method. You can even go as far as configuring diagnostic mode and collect local variables. Is this application in production? In production but I would be specific to a class to enable.

shawn