views:

55

answers:

2

Hi all,

Does anyone know how to watch a variable in calling function. For example: C#:

void fn a()
{
int myVar=9;
b();
}

b()
{
Throw new Exception();
}

How can I watch myVar when I get the exception in function b?? I have a really big recursive function with in a loop and get an exception in one iteration. I don't know which iteration it belongs to$%^&*(. The thing I did was to promote my intersted variable to global so I can watch them anywhere. However, I don't think that's a good idea only for debug.

Thanks everyone!

+1  A: 

You can use the the Stack Explorer to move to the stack frame (when in Debug and paused) and watch the values. The Stack Explorer displays all the calls leading up to the current one (the one you have paused in), and if you double click one it will jump to the location where it calls the method "underneath it" (actually above it in the explorer.)

Some calls, like some framework code and native calls will not be shown in the explorer, but they are usually of rare interest anyhow.

Edit: Apparently it's called Call Stack Window, use it every day and don't know what it is called - lol.

Skurmedel
+7  A: 

You need to use the Call Stack Window.

Simply choose the stack level the next level up, and the variable should now be in your Locals Window.

Also Stopping on First Chance Exceptions may also help.

kervin