Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error handling from non-Blazor events (e.g. Timer) #44871

Closed
Dreamescaper opened this issue Nov 4, 2022 · 1 comment
Closed

Error handling from non-Blazor events (e.g. Timer) #44871

Dreamescaper opened this issue Nov 4, 2022 · 1 comment
Labels
area-blazor Includes: Blazor, Razor Components

Comments

@Dreamescaper
Copy link

Dreamescaper commented Nov 4, 2022

Is your feature request related to a problem? Please describe the problem.

There seems to be no way to invoke non-Blazor event handlers with Blazor error handling. Let's say I have an ErrorBoundary wrapping some component. This component uses System.Timers.Timer class to refresh the data once a certain period. It uses InvokeAsync method (as suggested here). The problem, however, is that all the errors happening within those event handlers are not handled neither by ErrorBoundary, nor by Blazor's Renderer in general. The exception is simply lost, not even logged anywhere.

You can take a look this this sample project https://github.com/Dreamescaper/BlazorRepro44871. It has two buttons. The first one throws an exception after awating a delay (it is handled by ErrorBoudary successfully). Second one throws Exceptions in Timer's events (exceptions are ignored).

chrome_z8wiiaTFS9

Describe the solution you'd like

Ideally, ComponentBase.InvokeAsync method should handle exceptions, and push them through Blazor's error pipeline (probably catch the exception and pass it to Renderer.HandleExceptionViaErrorBoundary method).

If that's an unacceptable breaking change, a separate method or method overload should be added to handle this case.

The other option would be to make a public method on Renderer to handle the exception (similar to HandleExceptionViaErrorBoundary) so the user would be able to invoke it manually.

Additional context

This issue is quite similar to this closed item #27716, but with additional use case regarding ErrorBoundary.

@SteveSandersonMS
Copy link
Member

SteveSandersonMS commented Nov 7, 2022

Thanks! I've filed #44920 to track this. I agree we should create a suitable API for this.

Closing in favour of #44920

@ghost ghost locked as resolved and limited conversation to collaborators Dec 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components
Projects
None yet
Development

No branches or pull requests

3 participants