The New Global Error Handling in ASP.NET Core 8

preview_player
Показать описание

Error handling is critical for .NET APIs. I will split this video into two parts: errors I know how to handle and errors I don't know how to handle. For errors I know how to handle, I like using the Result pattern. It helps me get rid of exceptions and make my intent explicit. For errors I don't know how to handle, I'll use exceptions. To handle exceptions, I can create a global exception handler. This can be done using middleware or to hew IExceptionHandler in .NET 8.

Join my weekly .NET newsletter:

Read my Blog here:

Global Error Handling in ASP.NET Core 8

3 Ways To Create Middleware In ASP .NET Core

Chapters
0:00 Errors that you know how to handle
2:02 Problem Details standard error response
5:32 Handling exceptions with Middleware
9:29 Handling exceptions with IExceptionHandler
Рекомендации по теме
Комментарии
Автор

Very nice! Short, concise and very useful - keep up the excellent work, Milan.

MrAlkazam
Автор

Thank you mam.
Content is Perfect balance between very technical, useful and just about the right amount of watching time.
Keep 'em rolling

Targeting-Must-End
Автор

Thank you, Milan! Always up-to-date, I learned a lot from you in last month which helped me on my interviews!

f.d.
Автор

How to use this approach when we are using controllers ( not minimal api)

nirajchandrajoshi
Автор

Hey, Milan. Great work on your channel.
Quick question. Why would we need a middleware or implementing a custom IExceptionHandler in order to have logging and problem details for internal server errors? Isn't the default UseExceptionHandler middleware doing this already? Thanks, respect!

zdxzxzdxzx
Автор

Dear Milan, thank you for the amazing video. One thing that got me wondering was the Idea of multiple ExceptionHandlers, as you mentioned in your video. How could one ensure a specific order in which these Handlers would be invoqued in case of an Exception that came from an Endpoint from your controller? Ideally, I would suggest to always keep a GlobalExceptionHandler (just like the one you implemented in this video), plus any other specific Exception Handler.

I thank you for your time, and I hope to hear from you soon.

philiperiskallaleal
Автор

Is there ultimately any benefit of choosing one Vs the other approach?

Wese
Автор

Nice. Problem details object is a nice addition to the framework.

RanjeethMD
Автор

Nice video as always my friend! In which place did you put the ProblemDetails class?

nicolaimagnussen
Автор

Which validations should I run on the use cases, and which ones should I run on the domain?

alexramossilva
Автор

Good job.
One question, why did you name the folder as /Infrastructure inside the Api project and not other name, like: /ExceptionHandlers?
The old and traditional Middlewares you have put inside /Middlewares folder.
And finally, in a real project using some layered architecture, would you put this implementation inside Infra layer or Presentation (where the WebApi resides) layer? 🤔

haraheiquedossantos
Автор

Hi Milan, great video, but how should I create a exception filter to handle API errors in caller api project, for example blazor?

alfonsdeda
Автор

Hey Milan, what extension are you using for inline debug variable/parameter info?

sigtrygguradv
Автор

Thank you, Milan! Always Good Technical Video Post. I have one question. How to handle unauthorized controller in global. How to all generic message display error or status code wise?

achalprajapati
Автор

Hi Milan, I have .net 8 but my VS not recognize IExceptionHandler and his namespace. Can you give me some pointers?

davide
Автор

i have got a problem, i am using sth similar to what you are doing for middleware, but my methods are called by background tasks done with quartz jobs. If i am calling the method manually from swagger/postmen it works, but with jobs doesn t

dariusghita
Автор

Hi, where can i access the code you used in the demonstration please?. Great video!

shazaddin
Автор

Hi Milan, in the MVC Web Application, how to display the error message to view (/Home/Error)?

sky
Автор

Is this valid for webapps that work with blazor or just for web apis?

john
Автор

Is there a reason to use the IExceptionHandler instead of simply implementing your own middleware?

crutz