0

I am using ELMAH to log errors in my MVC3 project, using this HandleError attribute for expected exceptions.

My problem occurs when there are multiple HandleError attributes on an action. Elmah emails and logs the same exception for every HandleError attribute on the action, plus one.

The answer I linked to mentions this as a possible side-effect, but I'm at a loss as to how to solve the problem.

My largest concern is the action detailed below, as numerous exceptions are expected, and the user needs to see different reasons, and any of them may occur frequently.

[HandleError(ExceptionType = typeof(NotFoundException), View = "SomeErrorPage")]
[HandleError(ExceptionType = typeof(FaultException), View = "SomeErrorPage2")]
[HandleError(ExceptionType = typeof(RestrictedDrawingException), View = "SomeErrorPage3")]
[HandleError(ExceptionType = typeof(IOException), View = "SomeErrorPage4")]
public FileStreamResult ViewPdf(int id)
{
     ...
}
Community
  • 1
  • 1
damienc88
  • 1,957
  • 19
  • 34
  • why not *handle* the exceptions, instead? – Andrew Barber Jul 04 '12 at 02:52
  • My mistake, I mean, I need to show the user the reason for the failure. Should I do more than just show them that? I see no reason to. – damienc88 Jul 04 '12 at 03:13
  • I wouldn't give users that level of detail. Just tell them there was an error, youu have logged it, an will be investigating. Users don't care about types of errors... they just want it to work, or be friendly if it oesn't. and it could be a security threat to expose even the kind of error to a malicious user. – Andrew Barber Jul 04 '12 at 03:20
  • I mean, the error needs to be logged, and the user needs to be told what specifically went wrong (no very specific details are exposed, but for this site they do need to know what happened, and my company doesn't get a say in that), which means that attribute should be sufficient, but I'd love to hear your take on it, since I'm certainly not an expert on exception handling in MVC. – damienc88 Jul 04 '12 at 03:21

0 Answers0