Class ExceptionHandlingOptions

Configures exception normalizers for a single exception-handling middleware registration.

Inheritance
object
ExceptionHandlingOptions
JsonErrorDetailsOptions
Inherited Members
object.GetType()
object.MemberwiseClone()
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
Namespace: NanoRoute
Assembly: NanoRoute.dll
Syntax
public class ExceptionHandlingOptions
Remarks

New instances include the built-in AggregateException normalizer, which expands inner exceptions into developer messages. Each call to Map<TException>(TypedExceptionNormalizer<TException>) adds or replaces the normalizer for that exception type.

Examples
builder.AddExceptionHandler(options => options
    .Map<InvalidOperationException>(static ex => new HttpRequestException("Conflict", ex, HttpStatusCode.Conflict)));

Constructors

ExceptionHandlingOptions()

Initializes an exception-handling options instance with the built-in normalizers.

Declaration
public ExceptionHandlingOptions()
Remarks

The default options include an AggregateException normalizer that expands inner exceptions into developer messages.

Examples
ExceptionHandlingOptions options = new();

Properties

ExceptionNormalizers

Gets or sets the exception normalizers keyed by exception type.

Declaration
public Dictionary<Type, ExceptionNormalizer> ExceptionNormalizers { get; set; }
Property Value
Type Description
Dictionary<Type, ExceptionNormalizer>
Remarks

Exception handlers check the thrown exception's exact runtime type first, then walk base exception types until a normalizer is found. Use Map<TException>(TypedExceptionNormalizer<TException>) for typed registration, or replace this dictionary when a prebuilt normalizer set is easier to compose.

Examples
options.ExceptionNormalizers = options.ExceptionNormalizers.SetItem
(
    typeof(InvalidOperationException),
    static ex => new HttpRequestException("Conflict", ex, HttpStatusCode.Conflict)
);
Exceptions
Type Condition
ArgumentNullException

Thrown when the assigned value is null.

Methods

Map<TException>(TypedExceptionNormalizer<TException>)

Adds or replaces the normalizer used for TException and its derived exception types.

Declaration
public void Map<TException>(TypedExceptionNormalizer<TException> normalizer) where TException : Exception
Parameters
Type Name Description
TypedExceptionNormalizer<TException> normalizer

The normalizer that converts the exception into an enriched HttpRequestException.

Type Parameters
Name Description
TException

The exception type handled by normalizer.

Examples
options.Map<InvalidOperationException>(static ex => new HttpRequestException("Conflict", ex, HttpStatusCode.Conflict));
Exceptions
Type Condition
ArgumentNullException

Thrown when normalizer is null.

In this article
Back to top Generated by DocFX