【问题标题】:VS2017: Why is debugger breaking on handled exception when DebuggerNonUserCodeAttribute is used?VS2017:当使用 DebuggerNonUserCodeAttribute 时,为什么调试器会中断处理的异常?
【发布时间】:2019-05-12 10:43:33
【问题描述】:

当我使用 DebuggerNonUserCodeAttribute 并从委托或本地函数中抛出异常时,调试器会中断此异常。如果我按继续,则程序继续正常工作并处理异常。这很烦人。

这是错误还是功能?如何解决?

[DebuggerNonUserCode]
class Program {


    static void Main(string[] args) {
        try {
            Action act = () => throw new Exception( "Hello World !" );
            act();
        } catch (Exception ex) {
            Console.WriteLine( "Error" );
        }

        Console.Read();
    }


}

更新

Visual Studio 为什么写:Exception User-Unhandled?

【问题讨论】:

    标签: .net visual-studio debugging exception


    【解决方案1】:

    除非您更改了在抛出异常时中断的选项,否则它不应中断。验证它是否未选中。

    您可以通过取消选中 Exception Thrown 对话框中的选项 (Break when this exception type is thrown) 来做到这一点

    或转到Exception Settings (CTRL+ALT+e) 并取消选中该选项:

    【讨论】:

    • 我有一个更新的问题。我的例外设置是默认的。我可以取消选中Break when this exception type is thrown。但恐怕VS会忽略另一个例外。这不是好的解决方案。我想知道为什么DebuggerNonUserCodeAttribute 不改变调试器的行为。
    猜你喜欢
    • 1970-01-01
    • 2012-03-13
    • 2012-02-12
    • 2020-01-10
    • 1970-01-01
    • 2017-12-30
    • 1970-01-01
    • 2015-08-24
    • 1970-01-01
    相关资源
    最近更新 更多