liveBook · Manning

UseExceptionHandler

As explained in Building Web APIs with ASP.NET Core

UseExceptionHandler is an ASP.NET Core application-builder method that configures exception handling in the request pipeline.

UseExceptionHandler configures exception handling in the ASP.NET Core request pipeline. It can reexecute requests through an error endpoint or run custom middleware logic directly. section 6.2.4

Important implementation details:

  • The reexecuted request keeps the original HTTP method, so an error endpoint should not be limited to one verb unless separate handlers are intentional. section 6.2.4

Inline exception handling

UseExceptionHandler can accept an action that runs middleware directly. The handler serializes ProblemDetails to JSON and writes it into the HTTP response.

How Building Web APIs with ASP.NET Core covers it

How deep it goes
Explains endpoint reexecution and inline handling, including ProblemDetails serialization, but defers logging implementation.
Examples
Demonstrates an /error endpoint, a structured 500 response, trace identifiers, and an inline middleware handler.
What it assumes
Assumes familiarity with ASP.NET Core request pipelines, Minimal APIs, and ProblemDetails responses.
What you can do after
Apply it via ASP.NET Core to return consistent error responses and expose trace identifiers for failed requests.
How it connects
Connects exception-handling middleware with Minimal APIs, ProblemDetails, HTTP methods, and IExceptionHandlerPathFeature.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building Web APIs with ASP.NET Core. The section links point to the parts of the book it draws on.