调试器不破/停止在异步方法例外 [英] Debugger not breaking/stopping for exceptions in async method
本文介绍了调试器不破/停止在异步方法例外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当一个调试器附加到一个.NET过程中,它(通常)停止时未处理的异常。
When a debugger is attached to a .NET process, it (usually) stops when an unhandled exception is thrown.
不过,这似乎并没有当你在是工作异步
方法。
However, this doesn't seem to work when you're in an async
method.
在在以下code列出我尝试过的方案:
The scenarios I've tried before are listed in the following code:
class Program
{
static void Main()
{
// Debugger stopps correctly
Task.Run(() => SyncOp());
// Debugger doesn't stop
Task.Run(async () => SyncOp());
// Debugger doesn't stop
Task.Run((Func<Task>)AsyncTaskOp);
// Debugger stops on "Wait()" with "AggregateException"
Task.Run(() => AsyncTaskOp().Wait());
// Throws "Exceptions was unhandled by user code" on "await"
Task.Run(() => AsyncVoidOp());
Thread.Sleep(2000);
}
static void SyncOp()
{
throw new Exception("Exception in sync method");
}
async static void AsyncVoidOp()
{
await AsyncTaskOp();
}
async static Task AsyncTaskOp()
{
await Task.Delay(300);
throw new Exception("Exception in async method");
}
}
我缺少的东西吗?我怎样才能让调试器打破了例外,上/停止 AsyncTaskOp()
?
推荐答案
的调试
菜单下,选择例外...
。在例外对话框,旁边的公共语言运行库异常
行检查时抛出
框。
Under the Debug
menu, select Exceptions...
. In the Exceptions dialog, next to the Common Language Runtime Exceptions
line check the Thrown
box.
这篇关于调试器不破/停止在异步方法例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文