Search code examples
c#.netasp.net-mvcelmahelmah.mvc

Does Elmah handle unhandled exceptions from other layers?


I'm new to Elmah and considering implementing it in a project. It would be an ASP.NET MVC + Umbraco + EF web project which will have multiple layers (Business, DAL etc).

My interest in Elmah is its ability to handle unhandled exceptions.

But the question is does it handle unhandled exceptions from other layers (Services, Business, DAL etc) as well or just from Web layer (ASP.NET MVC) ?


Solution

  • ELMAH handles any exception thrown back to the client. This means that exceptions thrown in your data layer do not get logged, if you catch them in the MVC layer or anywhere else. You typically don't want exceptions from lower layers to end up at the client.

    ELMAH also supports manual logging of errors through ErrorSignal like this:

    try
    {
        database.DoSomeStuff();
    }
    catch (SomeDatabaseException ex)
    {
        Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
    }