Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

How do I handle exceptions in blazor server events

$
0
0

I'm trying to understand exception handling in Blazor Server (.net 7)

  1. My _Layout.cshtml has a dev with id blazor-error-ui. It displays if an unhandled exeption bubbles up in the application. Is Blazor server hardcoded to look for an element with that id, or is the behaviour wired up somewhere in an application?

  2. If my app raises an exception in an OnInitializedAsync, OnInitialized, OnAfterRender or OnAfterRender event, the exception will bubble up and the application will handle it. I'll see the error in the blazor-error-ui div. Expected behaviour.

  3. If I have a function which is bound to a property of a component, for example @bind-Value:after, and an exception is thrown in that function, the exception does not bubble up and display in the blazor-error-ui div.

  4. Further, if I have a component that has an event invoked by InvokeAsync, the exception does not bubble up and display in the blazor-error-ui div. The comppnent invoking the function is the Blazorise Tabs controls SelectedTabChanged event, which I beleive doesn't use an await on the InvokeAsync. The Clicked event of the Tab component uses an await, and those exceptions do display in the blazor-error-ui div. When should InvokeAsync be called with await vs not? Is that a bug in the component?

    protected override void OnInitialized(){throw new Exception("This exception will be seen.");}

    ...

    //This function is called by the Tabs component, using InvokeAsyncprivate void SelectedTabChanged(){throw new Exception("This exception will not be seen.");}

    <Tabs @bind-SelectedTab="SelectedTab"@bind-SelectedTab:after="AfterSelectedTabChanged">...

    private async Task AfterSelectedTabChanged(string tab){throw new Exception("This exception will not be seen.");}


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>