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
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:
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(); } } }
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); } }
Register the
MyTestExceptionService
service in theMySolution.Blazor.Server\Startup.cs
file:// ... services.AddXaf<MySolutionBlazorApplication>(Configuration); // Register the service. services.AddScoped<IExceptionHandlerService, MyTestExceptionService>(); // ...
Run the application and click the Test Action button. The user-friendly exception is displayed within a toast notification.