ExceptionService Class
A service that provides access to a custom exception handling.
Namespace: DevExpress.ExpressApp.Blazor.Services
Assembly: DevExpress.ExpressApp.Blazor.v24.1.dll
NuGet Package: DevExpress.ExpressApp.Blazor
Declaration
Remarks
Override the ExceptionService.HandleException(Exception) method in the class descendant to wrap an exception in a user-friendly exception.
The following example demonstrates how to display user-friendly exception 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.