2

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?

2
  • What are you asking? Without knowing your requirements its hard to tell whats missing. Number 2 also makes this question confusing, handling exceptions and other errors with user popups. Commented Aug 3, 2010 at 13:06
  • @jfar, in No. 2, a dev can catch an exception and return a result that shows the user the error in a popup in the returned view. Commented Aug 3, 2010 at 13:17

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.