I would like to be able to catch all unhandled exceptions in one single place building a Blazor single page application. Like using the "Current.DispatcherUnhandledException" in WPF applications.
This question is exclusively about client-side (webassembly) exception handling. I am using Blazor version 3.0.0-preview8.19405.7
I have been searching for a solution, but it seems like it does not exist. On Microsofts documentation (https://docs.microsoft.com/en-us/aspnet/core/blazor/handle-errors?view=aspnetcore-3.0) there is a list of places errors may occur and a walk through on how to handle each one of them. It believe there must be a more bullet proof way to catch all.
In .NET 6 there is component called ErrorBoundary.
<ErrorBoundary>
@Body
</ErrorBoundary>
For the global exception handling I see this as an option:
Create CustomErrorBoundary
(inherit the ErrorBoundary
) and override the OnErrorAsync(Exception exception)
.
Here is the sample of CustomErrorBoundary
.
ErrorBoundary
(youtube)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With