.. _refEventQueueExceptionHandler: ############################# Event Queue Exception Handler ############################# A Event Queue Exception Handler is a piece of logic that handles the errors produced by event handlers when are executed in background by the event queue. You can use it to handle the exceptions in any form you want. .. important:: In case of exception in one event handler the rest of the handlers will be executed and then an AggregateException will be generated. .. tip:: As good practices, try to control the exceptions in the event handler. Default Event Queue Exception Handler ===================================== This exception handler logs the errors using the ILogger based logging system. .. sourcecode:: csharp /// /// Default event dispatch exception handler that logs the exceptions /// public sealed class DefaultEventQueueExceptionHandler : IEventQueueExceptionHandler { private readonly ILogger _logger; /// /// Constructor /// /// public DefaultEventQueueExceptionHandler(ILogger logger) { _logger = logger; } /// /// Handles event dispatch exception /// /// Aggregate exception with all handlers errors /// Name of the event /// public Task Handle(AggregateException aggregateException, string eventName) { _logger.LogError(aggregateException, $"Errors occurred executing event {eventName}"); return Task.CompletedTask; } } Custom Event Queue Exception Handler ==================================== To create a Custom Event Queue Exception Handler you have to implement the ``IEventQueueExceptionHandler`` interface and then register it using ``AddCustomExceptionHandler`` method. See :ref:`Advanced configuration ` for details. .. sourcecode:: csharp /// /// Interface for implement an exception handler for the event queue dispatch strategy /// public interface IEventQueueExceptionHandler { /// /// Handles event queue dispatch strategy /// /// Aggregate exception with all handlers errors /// Name of the event /// Task Handle(AggregateException aggregateException, string eventName); }