简体   繁体   中英

Visual Studio 2008/2010 SP1, how to jump back out of a catch?

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...
}

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:

无法将下一个语句设置为此位置。尝试解除callstack失败。

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:

新项目平台

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:

  1. Debugging was started via Just-In-Time debugging.
  2. An unwind is in progress.
  3. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM