Table of Contents

Interface ITypedExceptionHandler<TException>

Namespace
Excalibur.Dispatch.Middleware.ErrorHandling
Assembly
Excalibur.Dispatch.dll

Defines a typed exception handler that processes exceptions of a specific type within the dispatch pipeline.

public interface ITypedExceptionHandler<in TException> where TException : Exception

Type Parameters

TException

The type of exception this handler processes.

Extension Methods

Examples

public class TenantResolutionFailureHandler : ITypedExceptionHandler<TenantResolutionException>
{
    public ValueTask<ExceptionHandlerResult> HandleAsync(
        TenantResolutionException exception,
        IDispatchMessage message,
        IMessageContext context,
        CancellationToken cancellationToken)
    {
        return ValueTask.FromResult(ExceptionHandlerResult.Handled(
            MessageResult.Failed("Tenant could not be resolved")));
    }
}

Remarks

Typed exception handlers enable fine-grained exception handling by routing specific exception types to dedicated handlers, in the shape of ASP.NET Core's IExceptionHandler. The scope differs from that of ASP.NET Core -- see below.

Register handlers in the container and add the middleware to the pipeline with UseTypedExceptionHandling(IDispatchBuilder). TypedExceptionHandlerMiddleware then resolves the matching handler when an exception escapes a pipeline component below it. Registration alone does not place the middleware in the pipeline, and without it no handler is consulted.

Scope. Handlers see faults raised by pipeline components. They do not see an exception thrown by the message handler itself: the terminal dispatch stage converts that into a failed IMessageResult before the pipeline unwinds, so no middleware observes it. Inspect the returned result for that case.

Methods

HandleAsync(TException, IDispatchMessage, IMessageContext, CancellationToken)

Handles the specified exception that occurred during message processing.

ValueTask<ExceptionHandlerResult> HandleAsync(TException exception, IDispatchMessage message, IMessageContext context, CancellationToken cancellationToken)

Parameters

exception TException

The exception to handle.

message IDispatchMessage

The message being processed when the exception occurred.

context IMessageContext

The message context at the time of the exception.

cancellationToken CancellationToken

The cancellation token to observe.

Returns

ValueTask<ExceptionHandlerResult>

A ValueTask<TResult> containing an ExceptionHandlerResult that indicates whether the exception was handled and the result to return.