Reputation: 81292
I am using the debugger (vs2008).
Once I've stepped into a catch statement, I would like to know if there is any way to set the execution cursor back to the beginning of the try.
Just dragging it there doesn't seem to work, is there some setting I need to change?
Example:
try
{
//Want the cursor back here
}
catch
{
//some code, cursor is here...
}
Upvotes: 3
Views: 1536
Reputation: 48486
Apparently it depends which flavor of .NET runtime you are using. At the time I first wrote this, it worked fine for me when I tried it, but I was using my work PC, with a 32-bit OS installed.
I'm using this code snippet to test:
try
{
throw new Exception();
}
catch
{
Console.WriteLine("Error"); // Breakpoint here
}
You can't set the cursor on the try
line. It will be on the line following immediately after it (the opening of the block statement).
Dragging the cursor to that line or the try
line works fine for me when I compile my .NET program for x86. It will also work if you're running a 32-bit OS. However, when you're on a 64-bit environment and compile for Any CPU or x64, you will get the following error message:
Since this is for debugging purposes only, a possible workaround for you would be to compile for x86, so the 32-bit runtime will be used. Go to the Build menu and choose Configuration Manager. Under Platform, select x86 or New... if it's not currently in the list. In the latter case, you'll get a new dialog. Pick the options as shown below and click OK:
Upvotes: 2
Reputation: 86729
If I right click and do "set next statement" then I get the following error dialog:
Unable to set the next statement to this location. The attempt to unwind the callstack failed.
Unwinding is not possible in the following scenarios:
- Debugging was started via Just-In-Time debugging.
- An unwind is in progress.
- A System.StackOverflowException or System.Threading.ThreadAbortException exception has been thrown.
By elimination the reason why you cant move the cursor (The same as setting the next statement) must be #2.
Upvotes: 1