全部,请取以下代码:
Task<bool> generateStageAsyncTask = null;
generateStageAsyncTask = Task.Factory.StartNew<bool>(() =>
{
return GenerateStage(ref workbook);
}, this.token,
TaskCreationOptions.LongRunning,
TaskScheduler.Default);
// Run core asynchroniously.
bool bGenerationSuccess = false;
try
{
bGenerationSuccess = await generateStageAsyncTask;
}
catch (OperationCancelledException e)
{
// Script cancellation.
result.RunSucceeded = true;
result.ResultInfo = "Script processing cancelled at the users request.";
return result;
}
从方法中GenerateStage
我测试并重新抛出 aOperationCancelledException
如下
try
{
...
}
catch (Exception e)
{
if (e.GetType() == typeof(OperationCanceledException))
throw e;
else // <- Here it is saying that the thrown exception is unhandled.
{
// Do other stuff...
}
}
但是在上面的指定行中,它声明重新抛出的异常未处理。我await
在上面的第一个代码片段中用适当的包装了我的try/catch
,为什么这try/catch
没有捕获重新抛出的异常?