Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Step through a program backwards after an Exception has occurred - Visual Studio

Is there a way to step back through a program from the point where an error/Exception has occurred? Or look at the sequence in which the methods were called before the error occurred?

like image 325
nf313743 Avatar asked Dec 10 '10 12:12

nf313743


People also ask

How do I step back in Visual Studio code?

These icons navigate the events in the Events Tab. So, if you've just taken a step in live debugging (F10 or F11), you can use the Step Backward button to quickly navigate to the previous step. This will automatically put Visual Studio in Historical debugging mode, at the line of code you've stepped back to.

How do I stop Visual Studio from breaking on exception?

To turn off stop on exceptions press " Ctrl + Alt + E ". This will open the Exceptions window . Untick "Common Language Runtime Exceptions - Thrown". That would prevent it from pausing from within the delegate, but not when it's rethrown on Wait .

How do I enable Break on exception in Visual Studio?

Tell the debugger to break when an exception is thrownIn the Exception Settings window (Debug > Windows > Exception Settings), expand the node for a category of exceptions, such as Common Language Runtime Exceptions. Then select the check box for a specific exception within that category, such as System.

How do I Debug a breakpoint in Visual Studio?

To set a breakpoint in source code: Click in the far left margin next to a line of code. You can also select the line and press F9, select Debug > Toggle Breakpoint, or right-click and select Breakpoint > Insert breakpoint. The breakpoint appears as a red dot in the left margin.


4 Answers

In the Ultimate versions of Visual Studio 2010 you can use Inellitrace to go back in the execution, as Dan Puzey mentioned.

However, in any version of Visual Studio you can still get a lot of information just from the call stack. It doesn't only show the calls that lead up to the current position, by double clicking on points in the Call Stack window you can jump to the point in the code where each method was called. The state of the stack is preserved, so you can even still see the values of local variables in the calling method.

like image 95
Guffa Avatar answered Oct 11 '22 09:10

Guffa


If you have VS2010 Ultimate, the "Intellitrace" functionality allows you to do exactly that. It basically logs a huge amount of execution data (up to and including every method call & parameter made) and allows you to step back in time to examine variable values at those points.

like image 21
Dan Puzey Avatar answered Oct 11 '22 11:10

Dan Puzey


You will see the trace in the Stack Trace (Call Stack Window in Visual Studio).

If you are using debugger you can drag and drop the yellow arrow to the previous lines of code to repeat the scenario. However, it does not always work.

like image 7
nan Avatar answered Oct 11 '22 10:10

nan


Right click on the line of code to which you want to get back and select "Set next statement" Another option is to drag the yellow arrow to the desired line.

like image 7
Andrei Karcheuski Avatar answered Oct 11 '22 10:10

Andrei Karcheuski