![](/img/trans.png)
[英]Catch / cancel an unhandled exception whilst debugging in Visual Studio
[英]Prevent Visual Studio debugging breaking on an apparent “unhandled exception”
請考慮這個簡短的控制台應用代碼。
static void Main(string[] args)
{
try
{
Action a = () =>
{
throw new ApplicationException("Oops");
};
var ar = a.BeginInvoke(null, null);
ar.AsyncWaitHandle.WaitOne();
try
{
a.EndInvoke(ar);
Console.WriteLine("No message");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
finally
{
Console.ReadKey();
}
}
當運行時,Visual Studio會在throw
抱怨它未經處理。 在調試器外部執行時,代碼執行我期望的操作(顯示“Oops”)。
我如何說服Visual Studio允許代碼像在現實世界中那樣執行?
您可以將DebuggerNonUserCode屬性應用於方法以將其從調試器中隱藏。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.