Global Exception Handler (In ASP.NET Core)

DotNet Core Central
DotNet Core Central
11.5 هزار بار بازدید - 4 سال پیش - When we forgot a have
When we forgot a have a proper try/catch block around our code, it creates a very odd exception response to the caller. Which is neither intended nor pretty. Thankfully ASP.NET Core provides middleware to solve this issue.

In this video, I am going to walk through step by step process of implementing a global exception handler for ASP.NET Core Web Application.

The extension method UseExceptionHandler on the IApplicationBuilder instance provides us with the capability to handler uncaught exceptions.

There are three main ways of implementing UseExceptionHandler middleware.
1. Using the string-based parameter, which contains the handler path which connects to a controller to handle the exception
2. Using an instance of ExceptionHandlerOptions
3. And finally using an Action, which passing an instance of IApplicationBuilder to create new middleware.

In the video, I will focus on the steps 1 and 2 for implementing the global exception handler. These two steps would cover 100% of the use cases out there.

The source code is available here: https://github.com/choudhurynirjhar/g...
4 سال پیش در تاریخ 1399/04/01 منتشر شده است.
11,530 بـار بازدید شده
... بیشتر