How I handle Exceptions in ASP.NET

Ikechi Michael
Apr 29, 2024

--

This is my preferred method of handling errors in ASP.NET projects. Perhaps, you’ll find it useful, or maybe you’ll find holes in it and poke at it in the comments, or improve it in your own projects.

I try to not have try-catch statements in controllers, preferring to use a GlobalExceptionFilter or whichever construct is most appropriate for the version of .NET I am using.

I have annotated the GlobalExceptionFilter code below, providing explanations for the choices I made.

--

--

Ikechi Michael

I’ve learned I don’t know anything. I've also learned that people will pay for what I know. Maybe that's why they never pay.