I want to handle uncaught exceptions in my ASP.NET MVC 3 application, so that I may communicate the error to the user via the application’s error view. How do I intercept uncaught exceptions? I’d like to be able to do this globally, not for each controller (although I wouldn’t mind knowing how to do this as well).
Share
You can set up a global error filter in
Global.asaxThe above sets up a default error handler which directs all exceptions to the standard error View. The error view is typed to a
System.Web.Mvc.HandleErrorInfomodel object which exposes the exception details.You also need to turn on custom errors in the web.config to see this on your local machine.
You can also define multiple filters for specific error types:
Note that
HandleErrorAttributewill only handle errors that happen inside of the MVC pipeline (i.e. 500 errors).