繁体   English   中英

Visual Studio 在已处理的异常上中断,就好像它是未处理的一样

[英]Visual Studio breaks on Handled Exception as if it was Unhandled

我使用 Activator.CreateInstance 从 Type 创建 class。 如果构造函数抛出异常(这种情况发生并且完全在意料之中),它会被 try..catch 捕获。
但是 Visual Studio 会中断,就好像它没有处理过一样。
我设法简化了这个问题:
VS 截图
Tio 中的代码

using System;

public class Program
{
  public static void Main()
  {
    try {
      var foo = Activator.CreateInstance(typeof(Foo));
    catch {}
    Console.WriteLine("Finished");
  }

  class Foo {
    public Foo() {
      throw new Exception();
    }
  }
}

如果这很重要,我使用 Visual Studio 2019

发生这种情况是因为您正在调试代码,甚至 Visual Studio 都表示已处理异常。

它是可配置的。 Go 到“调试 -> Windows -> 异常处理” window 并取消选中“公共语言运行时异常”中的所有异常,即使它们已处理(如果您想查看它们,也可以留下一些)。

另一个可能导致它的VS设置-选项->调试->“当异常跨越AppDomain或托管/本机边界时中断”启用

暂无
暂无

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

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