[英]Visual studio breaks on exception that IS handled with unhandled exception dialog
[英]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.