views:

65

answers:

1

I am trying in design a watertight exception handling strategy for an MVC application in which we use Elmah for logging unhandled exceptions. I would like some critique on some of my thoughts.

  1. All application exceptions should be handled in the controller layer. Any unhandled exception below that layer should be the result of a request from a controller.
  2. In the controllers, a developer can handle certain errors with user popups etc. with optional logging to Elmah.
  3. In the controllers, for unhandled errors, I can use a custom HandleError attribute to decide whether to just let Elmah log the error, or to also then proceed to the Error view.

Sound OK? Anything serious missing?

+1  A: 

You're on the right track. Check out the NerdDinner sample for some examples of handling errors in controllers.

In MVC, you can create a custom controller factory that will inject the HandleErrorWithElmah attribute into all of your controllers.

Check out my code project article that deals with logging in MVC - hope that helps.

Darren