【发布时间】:2014-06-03 09:50:42
【问题描述】:
我正在使用Steven Toub's excellent AsyncPump class,它允许控制台应用程序使用 async/await 关键字。
但是,我有一个问题,代码中抛出的异常被泵捕获然后重新抛出,这导致原始调用堆栈和异常上下文丢失。
这是我的测试代码:
class Program
{
static void Main(string[] arg)
{
AsyncPump.Run(() => MainAsync());
}
static async Task MainAsync()
{
throw new Exception(); // code should break here
}
}
如果您运行此测试,调试器不会根据需要在 throw new Exception() 上中断。相反,它在 t.GetAwaiter().GetResult() 上中断,这是 AsyncPump 类本身的一部分。这使得调试应用程序变得非常困难。
有没有办法重新抛出异常,使调试器在原始位置中断,同时保留调用堆栈和上下文?
【问题讨论】:
标签: c# exception-handling console async-await