最佳答案
使用微软的。net异步CTP, 是否有可能在调用方法中捕获异步方法抛出的异常?< / p >
public async void Foo()
{
var x = await DoSomethingAsync();
/* Handle the result, but sometimes an exception might be thrown.
For example, DoSomethingAsync gets data from the network
and the data is invalid... a ProtocolException might be thrown. */
}
public void DoFoo()
{
try
{
Foo();
}
catch (ProtocolException ex)
{
/* The exception will never be caught.
Instead when in debug mode, VS2010 will warn and continue.
The deployed the app will simply crash. */
}
}
所以基本上我想从异步代码的异常冒泡到我的调用代码
如果这是可能的,