►► Master Web API development Best Practices:
►► Build great web apps in Blazor WebAssembly:
►► Support us on Patreon and get the source code:
UPDATED CONTENT (.NET 8):
The exception-handling features help us deal with the unforeseen errors that could appear in our code. Let's learn how to implement it.
FOLLOW US ON SOCIAL MEDIA!
►►
►►
►►
VIDEO SUMMARY:
Even though there is nothing wrong with the try-catch blocks in our Actions in Web API project, we can extract all the exception-handling logic into a single centralized place.
By doing that, we make our actions more readable and the error-handling process more maintainable. If we want to make our actions even more readable and maintainable, we can implement Action Filters.
We won’t talk about action filters in this article but we strongly recommend reading our post Action Filters in .NET Core.
In this video, we are going to handle errors by using a try-catch block first and then rewrite our code by using built-in middleware and our custom middleware for global error handling to demonstrate the benefits of this approach.