Skip to main content
All docs
V24.2
.NET 8.0+
  • The page you are viewing does not exist in the .NET Framework 4.6.2+ platform documentation. This link will take you to the parent topic of the current section.

ExceptionService Class

A service that allows you to handle exceptions in a custom manner.

Namespace: DevExpress.ExpressApp.Blazor.Services

Assembly: DevExpress.ExpressApp.Blazor.v24.2.dll

NuGet Package: DevExpress.ExpressApp.Blazor

Declaration

public class ExceptionService :
    IExceptionHandlerService,
    IExceptionProviderService

Remarks

Note

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

Override the ExceptionService.HandleException(Exception) method in the class descendant to wrap an exception in a user-friendly exception.

The following example displays a user-friendly exception message in your XAF Blazor UI application:

  1. Add a controller:

    using DevExpress.ExpressApp;
    using DevExpress.ExpressApp.Actions;
    using System;
    
    namespace MySolution.Module.Controllers {
        public class MyTestException : Exception {
        }
    
        public partial class TestExceptionController : ViewController {
            public TestExceptionController() {
                // When a user clicks this action, an exception is thrown.
                SimpleAction simpleAction = new SimpleAction(this, "Test Action", DevExpress.Persistent.Base.PredefinedCategory.Edit);
                simpleAction.Execute += SimpleAction_Execute;
            }
    
            private void SimpleAction_Execute(object sender, SimpleActionExecuteEventArgs e) {
                throw new MyTestException();
            }
        }
    }
    
  2. Add a MyTestExceptionService service and override the HandleException method:

    public class MyTestExceptionService : ExceptionService {
        public MyTestExceptionService(ILogger<ExceptionService> logger) : base(logger) { }
        public override void HandleException(Exception exception) {
            Exception result = exception is MyTestException ? new UserFriendlyException("My Test User Friendly Exception", exception) : exception;
            base.HandleException(result);
        }
    }
    
  3. Register the MyTestExceptionService service in the MySolution.Blazor.Server\Startup.cs file:

    // ...
    services.AddXaf<MySolutionBlazorApplication>(Configuration);
    // Register the service.
    services.AddScoped<IExceptionHandlerService, MyTestExceptionService>();
    // ...
    
  4. Run the application and click the Test Action button. The user-friendly exception is displayed within a toast notification.

    xaf blazor user friendly url

Inheritance

Object
ExceptionService
See Also