ExceptionHandlerMiddleware
ExceptionHandlerMiddleware is ASP.NET Core HTTP middleware that intercepts unhandled exceptions and generates or redirects to an error response.
ASP.NET Core in Action, 3e
Error-handling middleware is middleware that intercepts application errors and modifies the HTTP response before it is returned to the client.
- How it is used
- Handles unhandled application exceptions in production middleware pipelines while returning controlled, user-friendly responses.
- How deep it goes
- Explains response replacement, environment-based registration, and pipeline reexecution, but defers building custom middleware.
- Examples
- Uses /error endpoints, generic JSON or plain-text responses, and branded Razor Pages error pages as concrete handlers.
- What you can do after
- Configure it via UseExceptionHandler to deliver safe production error responses without exposing sensitive application details.
Read how ASP.NET Core in Action, 3e explains ExceptionHandlerMiddleware →
Building Web APIs with ASP.NET Core
ExceptionHandlingMiddleware is HTTP middleware that catches exceptions and forwards relevant error information to a configurable error handler.
- How it is used
- Handles application-level HTTP exceptions safely in staging and production while routing failures to a controlled error endpoint.
- How deep it goes
- Explains environment selection, route implementation, response generation, testing, and customization, but not middleware internals.
- Examples
- Uses /error controller and Minimal API endpoints, deliberate test exceptions, and environment or configuration switches.
- What you can do after
- Operate/configure ASP.NET Core exception handling with a safe error route and customize status codes, logging, or notifications.
Read how Building Web APIs with ASP.NET Core explains ExceptionHandlerMiddleware →
Also covered in
Related concepts
- middlewarekind of · Middleware is software that mediates communication or processing between components, often by intercepting, transforming, or coordinating operations in a pipeline.
- UseExceptionHandlerconfigured by · UseExceptionHandler is an ASP.NET Core pipeline-extension method that configures handling for unhandled exceptions.
- IProblemDetailsServiceuses · IProblemDetailsService is an ASP.NET Core service interface that generates Problem Details responses for errors.
- pipeline reexecutionuses · Pipeline reexecution is the process of running a request-processing middleware pipeline again for a different path after an exception or other handling condition.
- DeveloperExceptionPageMiddlewarealternative to · DeveloperExceptionPageMiddleware is ASP.NET Core middleware that catches unhandled pipeline exceptions and generates a detailed diagnostic error page for developers.
- exception filteralternative to · An exception filter is an ASP.NET Core MVC filter that processes exceptions not handled by an endpoint or other applicable filters.
Questions about ExceptionHandlerMiddleware
What is ExceptionHandlerMiddleware?
ExceptionHandlerMiddleware is ASP.NET Core HTTP middleware that intercepts unhandled exceptions and generates or redirects to an error response.
Which Manning books explain ExceptionHandlerMiddleware?
ASP.NET Core in Action, 3e and Building Web APIs with ASP.NET Core.
What is the difference between ExceptionHandlerMiddleware and DeveloperExceptionPageMiddleware?
ExceptionHandlerMiddleware is ASP.NET Core HTTP middleware that intercepts unhandled exceptions and generates or redirects to an error response. DeveloperExceptionPageMiddleware is ASP.NET Core middleware that catches unhandled pipeline exceptions and generates a detailed diagnostic error page for developers.
What is ExceptionHandlerMiddleware a kind of?
ExceptionHandlerMiddleware is a kind of middleware. Middleware is software that mediates communication or processing between components, often by intercepting, transforming, or coordinating operations in a pipeline.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

