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; await task;
} }
catch when (task.IsCanceled) catch // avoiding exception filters for AOT runtime support
{ {
// Ignore exceptions from task cancelletions. // Ignore exceptions from task cancelletions.
// Awaiting a canceled task may produce either an OperationCanceledException (if produced as a consequence of // 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). // 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. // 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. // Don't call StateHasChanged here. CallOnParametersSetAsync should handle that for us.
@ -247,10 +251,15 @@ namespace Microsoft.AspNetCore.Components
{ {
await task; 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. // Ignore exceptions from task cancelletions, but don't bother issuing a state change.
return; if (task.IsCanceled)
{
return;
}
throw;
} }
StateHasChanged(); StateHasChanged();

View File

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