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.

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

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.

Override the ExceptionService.ShouldHandleException(Exception) method in the class descendant to determine how you want to process exceptions.

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 bool ShouldHandleException(Exception exception) {
            if(exception is MyException) {
                return true;
            }
            else {
                return false;
            }
        }
        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.

#Inheritance

Object
ExceptionService
See Also