Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to jump back to the line of code that threw exception in Visual Studio 2010 debugger?

Using the Visual Studio 2010 debugger, I am familiar with using the Call Stack window to see where the currently executing function was invoked from.

I'm working with some applications that have rather large try blocks. Supposing that I pause execution of the code at a break point in the catch block, what is the simplest way to tell which line in the try block the exception was raised from?

I do know that the "Stack Trace" includes details such as the line number, but is there an easier way, such as a shortcut key, to navigate back to the line of code where the exception was raised?

Update: I would like to emphasize that I don't wish to move the execution point back to the try block; I simply want a simpler way of knowing which line the exception was raised from.

like image 786
Vivian River Avatar asked Feb 21 '13 19:02

Vivian River


3 Answers

If you goto "DEBUG", "Exceptions..." and then select "Thrown" against "Common Language Runtime Exceptions".

Exceptions

Then when your code encounters an exception it will stop on the line with the error.

like image 175
DaveShaw Avatar answered Nov 20 '22 00:11

DaveShaw


A solution might be to make VS break on all exceptions:

Select Exceptions under the Debug menu, and check the "Thrown" box related to Common Language Runtime Exceptions.

Now VS should now stop and mark the line where the exception is thrown. You can continue as usual, by clicking the play button or F5.

The downside of this is that all exceptions will be caught in the same way, which may be annoying if you have a lot of them.

like image 23
Kjartan Avatar answered Nov 19 '22 23:11

Kjartan


For Visual Studio 2019:

Go to Debug -> Windows -> Exception Settings and mark every exception under Common Language Runtime Exceptions.

enter image description here

like image 1
Ogglas Avatar answered Nov 19 '22 23:11

Ogglas