简体   繁体   English

Visual Studio 2008/2010 SP1,如何跳出catch?

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

I am using the debugger (vs2008). 我正在使用调试器(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. 一旦我进入了catch语句,我想知道是否有任何方法可以将执行光标设置回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. 显然,它取决于您使用的.NET运行时的风格。 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. 在我第一次写这篇文章的时候,当我尝试它时,它对我来说很好,但我正在使用我的工作PC,安装了32位操作系统。

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. 您不能将光标设置在try行上。 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. 当我编译x86的.NET程序时,将光标拖动到该行或try行对我来说很好。 It will also work if you're running a 32-bit OS. 如果您运行的是32位操作系统,它也可以工作。 However, when you're on a 64-bit environment and compile for Any CPU or x64 , you will get the following error message: 但是,当您在64位环境中并为任何CPUx64编译时,您将收到以下错误消息:

无法将下一个语句设置为此位置。尝试解除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. 由于这仅用于调试目的,因此可能的解决方法是为x86编译,因此将使用32位运行时。 Go to the Build menu and choose Configuration Manager . 转到“ 生成”菜单,然后选择“ 配置管理器” Under Platform , select x86 or New... if it's not currently in the list. Platform下 ,选择x86New ...如果它当前不在列表中。 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: 如果我右键单击并执行“set next statement”,则会出现以下错误对话框:

Unable to set the next statement to this location. 无法将下一个语句设置为此位置。 The attempt to unwind the callstack failed. 尝试解除callstack失败。

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. 抛出了System.StackOverflowException或System.Threading.ThreadAbortException异常。

By elimination the reason why you cant move the cursor (The same as setting the next statement) must be #2. 通过消除你不能移动光标的原因(与设置下一个语句相同)必须是#2。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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