I am trying to install and test ELMAH for the fist time. I think I have setup everything correctly. I know ELMAH is designed to log unhandled exceptions. I use a standard template MVC 4 application generated by Visual Studio 2012
In a HomeControler class I throw an error without try and catch block
public ActionResult About()
{
// Throw a test error so that we can see that it is handled by Elmah
// To test go to the ~/elmah.axd page to see if the error is being logged correctly
throw new Exception("A test exception for ELMAH");
return View();
}
In my opinion this an unhandled exception.
Further I use a HandleErrorWithELMAHAttribute class to handle the error. This construct is shown in many ELMAH tutorials originally posted here:
How to get ELMAH to work with ASP.NET MVC [HandleError] attribute?
The code that bothers me is:
public override void OnException(ExceptionContext context)
{
base.OnException(context);
var e = context.Exception;
if (!context.ExceptionHandled // if unhandled, will be logged anyhow
|| RaiseErrorSignal(e) // prefer signaling, if possible
|| IsFiltered(context)) // filtered?
return;
LogException(e);
}
In the if statement the property contect.ExceptionHanled is checked. This property is set to true, so the thrown error is not logged.
Can you explain why it is set to true while there is no try-catch.
Best Regards, Sebastian