调试时无法设置下一条语句 [英] Unable to set next statement when debugging

查看:70
本文介绍了调试时无法设置下一条语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 VS2015 中调试我的项目,并且在我的代码中抛出了异常.当我尝试设置下一个语句时,我收到下面显示的错误消息.当我在 VS2013 中调试相同的解决方案时,我可以毫无问题地设置下一个语句.对于多种异常,这种行为似乎都会发生.

I am debugging my project in VS2015 and an exception is thrown in my code. When I try to set the next statement I get the error message displayed below. When I debug the same solution in VS2013 I am able to set the next statement without any problems. This behavior seems to occur for multiple kinds of exceptions.

我可以重现问题的示例代码如下所示.当在 TestMethod1 的最后一行抛出异常时,我可以轻松地回到 VS2013 中的第一个语句,但在 VS2015 中则不然.

Example code that I can reproduce the problem with is shown below. When an exception is thrown on the last line in TestMethod1 I can easily move back to the 1st statement in VS2013 but not in VS2015.

[TestClass]
public class UnitTest1
{
    [TestMethod]
    public void TestMethod1()
    {
        object o = new object();
        o = null;
        var e = o.ToString();
    }
}

推荐答案

在异常设置中,您需要为正在抛出的特定 CLR 异常类型启用 Break When Thrown,或者 <All Common Language Runtime Exceptions not in this列表>对于自定义异常.在此特定示例中,启用 System.NullReferenceException 应该允许您按预期设置下一条语句.

In Exception Settings, you need to enable Break When Thrown for the particular CLR exception type that is being thrown, or <All Common Language Runtime Exceptions not in this list> for custom exceptions. In this particular example, enabling System.NullReferenceException should allow you to set next statement as expected.

如果您想要中断特定的自定义异常而不中断所有未列出的 CLR 异常,您可以将它们添加到异常设置中的列表中并进行相应选择.

If there are particular custom exceptions you want to break on without breaking on all unlisted CLR exceptions, you can add them to the list in Exception Settings and choose accordingly.

我在 MSDN 上询问过这个问题,并从那里转发信息.[来源]

I asked about this on MSDN and am relaying info from there. [Source]

这篇关于调试时无法设置下一条语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆