【发布时间】:2015-04-14 11:11:14
【问题描述】:
有没有办法在 catch 块中调用 async 方法?
目前我有一个应用程序,它使用 async / awaited 方法记录异常,但我不能把它放在一个 catch 块中,因为有人告诉我:
The 'await' operator cannot occur inside a catch or finally block of a try-statement, inside the block of a lock-statment or in an unsafe context.
目前我必须将异常分配给 catch 块内的变量,然后调用我的await logException()。
虽然这不是世界末日,但似乎应该/可能有另一种/更好的方式。
有什么想法吗?
【问题讨论】:
标签: c# async-await