Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to see variable in calling function in visual studio?

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!

like image 592
Frank Avatar asked Oct 26 '25 10:10

Frank


2 Answers

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.

like image 129
kervin Avatar answered Oct 28 '25 22:10

kervin


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.

like image 41
Skurmedel Avatar answered Oct 29 '25 00:10

Skurmedel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!