Avoid using exception filters for AOT runtimes

This commit is contained in:
Larry Ewing 2019-05-06 18:59:34 -05:00 committed by Ryan Nowak
parent e0007f4f4b
commit a36a57df65
2 changed files with 18 additions and 8 deletions

View File

@ -208,12 +208,16 @@ namespace Microsoft.AspNetCore.Components
{
await task;
}
catch when (task.IsCanceled)
catch // avoiding exception filters for AOT runtime support
{
// Ignore exceptions from task cancelletions.
// Awaiting a canceled task may produce either an OperationCanceledException (if produced as a consequence of
// CancellationToken.ThrowIfCancellationRequested()) or a TaskCanceledException (produced as a consequence of awaiting Task.FromCanceled).
// It's much easier to check the state of the Task (i.e. Task.IsCanceled) rather than catch two distinct exceptions.
if (!task.IsCanceled)
{
throw;
}
}
// Don't call StateHasChanged here. CallOnParametersSetAsync should handle that for us.
@ -247,10 +251,15 @@ namespace Microsoft.AspNetCore.Components
{
await task;
}
catch when (task.IsCanceled)
catch // avoiding exception filters for AOT runtime support
{
// Ignore exceptions from task cancelletions, but don't bother issuing a state change.
return;
if (task.IsCanceled)
{
return;
}
throw;
}
StateHasChanged();

View File

@ -523,12 +523,13 @@ namespace Microsoft.AspNetCore.Components.Rendering
{
await updateDisplayTask;
}
catch when (updateDisplayTask.IsCanceled)
{
return;
}
catch when (updateDisplayTask.IsFaulted)
catch // avoiding exception filters for AOT runtimes
{
if (updateDisplayTask.IsCanceled)
{
return;
}
HandleException(updateDisplayTask.Exception);
return;
}