Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the current exception in blazor Error Boundary

I have an exception that has been generated in a certain context of my application. I would like to be able to collect it, send it to the logger and recover the previous state. Scenario

The problem is that this error-bound exception cannot be accessed since its current exception property is protected. enter image description here

What would be the solution?

like image 321
hesolar Avatar asked Mar 24 '26 07:03

hesolar


1 Answers

I had the same problem and after investigating the source code it was easy to get the current exception from ErrorContent of the ErrorBoundary.

<ErrorBoundary>
                    <ChildContent>
                        @Body
                    </ChildContent>
                    <ErrorContent Context="Exception">
                        <div>
                             @Exception.Message<br/>
                        </div>
                    </ErrorContent>
                </ErrorBoundary>

Get the current exception from the Context (RenderFragment) of ErrorContent (see above code example).

ErrorBoundaryBase ->

/// <summary>
    /// The content to be displayed when there is an error.
    /// </summary>
    [Parameter] public RenderFragment<Exception>? ErrorContent { get; set; }
like image 94
NetProvoke Avatar answered Mar 26 '26 20:03

NetProvoke



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!