Skip to main content
All docs
V26.1
  • ExceptionService.ShouldHandleException(Exception) Method

    Specifies whether the ExceptionService should handle the specified exception.

    Namespace: DevExpress.ExpressApp.Blazor.Services

    Assembly: DevExpress.ExpressApp.Blazor.v26.1.dll

    NuGet Package: DevExpress.ExpressApp.Blazor

    Declaration

    public virtual bool ShouldHandleException(
        Exception exception
    )

    Parameters

    Name Type Description
    exception Exception

    The processed exception.

    Returns

    Type Description
    Boolean

    true to handle the exception with the ExceptionService; false to handle the exception with the error boundary mechanism.

    Remarks

    The ShouldHandleException method returns true for exceptions that implement the IUserFriendlyException interface, and the ExceptionService processes these exceptions. For all other exceptions, the method returns false, and XAF passes the exceptions to the error boundary mechanism instead.

    Override the ShouldHandleException method to change this default behavior and specify which exceptions the ExceptionService should process.

    If the ShouldHandleException method returns true for an exception, the ExceptionService calls its HandleException(Exception) method to process that exception.

    The following code snippet overrides the ShouldHandleException method so that the ExceptionService also processes the custom MyCustomException exception:

    using DevExpress.ExpressApp.Blazor.Services;
    using Microsoft.Extensions.Logging;
    using DevExpress.ExpressApp;
    
    public class MyCustomException : Exception { }
    // ...
    public class CustomExceptionHandlerService : ExceptionService {
        public CustomExceptionHandlerService(ILogger<ExceptionService> logger) : base(logger) { }
        public override bool ShouldHandleException(Exception exception) {
            if(exception is MyCustomException) {
                return true;
            }
            else {
                return false;
            }
        }
        public override void HandleException(Exception exception) {
            Exception result = exception is MyCustomException ? new UserFriendlyException("A user-friendly exception message.", exception) : exception;
            base.HandleException(result);
        }
    }
    

    Important

    Refer to the ExceptionService class description to learn how to register the service in your application.

    See Also