There's more...

We could manage exceptions globally by creating an Exception middleware.

Since Web API 2.1, we use IExceptionHandler to handle exceptions globally. It helps catch exceptions in controllers, actions, filters, routes, and sometimes, MessageHandlers and MediaTypeFormatters.

We can also think about creating a custom global Exception filter to log the exception, but we will talk about that in Chapter 12, Filters.

Get ASP.NET Core MVC 2.0 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.