views:

128

answers:

2

I'm trying to find a way to automate some exception logging code to add to the stack information already available.

Is there any way to use reflection to retrieve the values of all variables on the stack (locals and parameters) - I sincerely doubt the names of the variables are available, but in many cases it would be useful to see the values.

+2  A: 

Not really. For this level of digging you'd probably need something like WinDbg.

If a specific variable is of interest, you can add it to the exception yourself (although even this introduces issues with duplicate keys, re-entrancy, etc):

    string dir = ...todo...
    try
    {
        // some code
    }
    catch (Exception ex)
    {
        ex.Data.Add("dir", dir);
        throw;
    }
Marc Gravell
A: 

You might check out John Robbins' SUPERASSERT (SUPERASSERT Goes .Net), his book gives a great walkthrough of one way to do what you are after (plus a WHOLE lot more).

Jason Haley