3

全部,请取以下代码:

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没有捕获重新抛出的异常?

4

1 回答 1

2

这是来自 Microsoft Connect 的同一问题的支持请求。禁用“只是我的代码”

Tools-> Options-> Debugging->General

解决问题。

于 2013-02-12T19:37:30.907 回答