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

冷暖自知 提交于 2019-12-07 15:26:38

问题


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

回答1:


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:




回答2:


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.



来源:https://stackoverflow.com/questions/2005386/visual-studio-2008-2010-sp1-how-to-jump-back-out-of-a-catch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!