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

    Processes the specified exception.

    Namespace: DevExpress.ExpressApp.Blazor.Services

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

    NuGet Package: DevExpress.ExpressApp.Blazor

    Declaration

    public virtual void HandleException(
        Exception exception
    )

    Parameters

    Name Type Description
    exception Exception

    The exception to process.

    Remarks

    XAF calls the HandleException method to process an exception when the ShouldHandleException(Exception) method returns true for that exception. ShouldHandleException returns true by default for exceptions that implement the IUserFriendlyException interface.

    Override the HandleException method to customize exception processing, for example, by wrapping an exception in a user-friendly exception (IUserFriendlyException) before XAF displays it to the user.

    The following code snippet overrides the HandleException method to wrap a custom MyCustomException in a UserFriendlyException object:

    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) =>
            exception is MyCustomException;
        public override void HandleException(Exception exception) {
            Exception result = exception is MyCustomException ? new UserFriendlyException("A user-friendly exception message.", exception) : exception;
            base.HandleException(result);
        }
    }
    

    Important

    For information about how to register the service in your application, see the ExceptionService class description.

    For more information about the default error processing mechanism in XAF ASP.NET Core Blazor applications, refer to the following topic: Error Handling in XAF ASP.NET Core Blazor.

    See Also