Let's say i have a custom object that raises an event when it errors and I attach a handler method.
Both of these handlers in the code snippet, in development, will make the debugger break to the exception line and if you press "continue" the whole app crashes instead of showing the usual Blazor error UI. I get that the void version run in another thread, but even with InvokeAsync
it does the same...I guess it's because it's not exactly as running code in the UI thread like i was throwing an exception in the OnInitialized
or some other method of a component.
I'm not sure if it would be better to log the error, but for example imagine having a debouncer for a search bar and the callback fails. I don't want to just log this event and the user is confused on what to do because nothing is working... Sure I could show a custom error component but can't I make it like any other blazor exception and show the default error UI? I guess since it's a search operation that can be done multiple times and it's not a fundamental part of showing a page, it's ok to just tell the user to retry, provided this error is transient. But here is opinionated territory i guess.
In production would the whole app stop and need to be restarted?
private void HandleSomeEvent(Object sender, Exception ex)
{
throw new InvalidOperationException("SomeEvent error", ex);
}
private async void HandleSomeEventAsync(Object sender, Exception ex)
{
await InvokeAsync(() => throw new InvalidOperationException("SomeEvent error", ex));
}