All please enter the following code:
Task<bool> generateStageAsyncTask = null;
generateStageAsyncTask = Task.Factory.StartNew<bool>(() =>
{
return GenerateStage(ref workbook);
}, this.token,
TaskCreationOptions.LongRunning,
TaskScheduler.Default);
bool bGenerationSuccess = false;
try
{
bGenerationSuccess = await generateStageAsyncTask;
}
catch (OperationCancelledException e)
{
result.RunSucceeded = true;
result.ResultInfo = "Script processing cancelled at the users request.";
return result;
}
From the method GenerateStageI test and re-throw a OperationCancelledExceptionas follows
try
{
...
}
catch (Exception e)
{
if (e.GetType() == typeof(OperationCanceledException))
throw e;
else
{
}
}
But the above line indicates that the repeated exception is unhandled. I wrap my own awaitin the first code snippet above with the corresponding one try/catch, why try/catchdoesn't this catch the repeated exception?
source
share