ExceptionService Class
A service that allows you to customize how XAF-related exceptions are handled.
Namespace: DevExpress.ExpressApp.Blazor.Services
Assembly: DevExpress.ExpressApp.Blazor.v26.1.dll
NuGet Package: DevExpress.ExpressApp.Blazor
Declaration
Remarks
The ExceptionService exposes two methods:
- ShouldHandleException(Exception)
- Override this method to specify whether the
ExceptionServiceshould process an exception. - HandleException(Exception)
- Override this method to process an exception, for example, to wrap it in a user-friendly exception (
IUserFriendlyException) or customize the user-friendly text.
The following example displays a user-friendly exception message in your XAF Blazor UI application:
Add a controller:
using DevExpress.ExpressApp; using DevExpress.ExpressApp.Actions; using System; namespace MySolution.Module.Controllers { public class MyCustomException : Exception { } public 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 MyCustomException(); } } }Add the
MyCustomExceptionServiceservice. Override the ShouldHandleException(Exception) method to specify that the service should process theMyCustomExceptionexception, and override the HandleException(Exception) method to wrap this exception in a user-friendly exception:using DevExpress.Data.Exceptions; using DevExpress.ExpressApp.Blazor.Services; // ... public class MyCustomExceptionService : ExceptionService { public MyCustomExceptionService(ILogger<ExceptionService> logger) : base(logger) { } public override bool ShouldHandleException(Exception exception) { if(exception is MyCustomException) { return true; } else { return base.ShouldHandleException(exception); } } public override void HandleException(Exception exception) { Exception result = exception is MyCustomException ? new UserFriendlyException("My Test User Friendly Exception", exception) : exception; base.HandleException(result); } }Register the
MyCustomExceptionServiceservice in theMySolution.Blazor.Server\Startup.csfile:// ... services.AddXaf<MySolutionBlazorApplication>(Configuration); // Register the service. services.AddScoped<IExceptionHandlerService, MyCustomExceptionService>(); // ...Run the application and click the Test Action button. The user-friendly exception is displayed in a toast notification.

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.