How to implement global exception handling in ASP.Net Core Web API

Take advantage of the UseExceptionHandler middleware in ASP.Net Core to ensure that every error in your Web API application is caught

Become An Insider

Sign up now and get FREE access to hundreds of Insider articles, guides, reviews, interviews, blogs, and other premium content. Learn more.

Exceptions are runtime errors that occur in an application. If they are not handled properly, the running program is terminated. How can we prevent that from happening? We can ensure that all unhandled exceptions are caught by using a global exception handler.

To implement global exception handling in ASP.Net Core Web API, we can take advantage of the built-in middleware UseExceptionHandler. A middleware is a software component inserted into the request processing pipeline that handles requests and responses.

When building an ASP.Net Core application, we can leverage various middleware components to customize the handling of requests and responses, and even inspect, route, or modify the request and response messages that flow through the pipeline.

In this post I will show how we can use the UseExceptionHandler middleware to handle exceptions globally in ASP.Net Core Web API.

Create an ASP.Net Core Web API project in Visual Studio 2017

To continue reading this article register now