I'm trying to understand exception handling in Blazor Server (.net 7)
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?If my app raises an exception in an
OnInitializedAsync,OnInitialized,OnAfterRenderorOnAfterRenderevent, the exception will bubble up and the application will handle it. I'll see the error in theblazor-error-uidiv. Expected behaviour.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 theblazor-error-uidiv.Further, if I have a component that has an event invoked by
InvokeAsync, the exception does not bubble up and display in theblazor-error-uidiv. 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 theblazor-error-uidiv. When shouldInvokeAsyncbe 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.");}