The Self-Taught Programmer

Recipes from real-world experience with asp.net.

Posts Tagged ‘Elmah

Elmah Signaling – How To Log Exceptions with Elmah but Continue Processing

leave a comment »

Elmah is an excellent tool for web programmers. It is an extremely easy to install exception handler that logs application exceptions and sends the user to an “oops” page. It can also send an email to the developer or webmaster.

But what if you want to log an error but NOT send the user to an “oops” page. This can be especially useful in debugging code that already handles exceptions so that the user doesn’t see them.

Here is how it works:

Add a reference to Elmah to the page:

using Elmah;

Then, in your try/catch block, use this code:

try
{
    //some code}
catch (Exception ex)
{
    // handle your exception here
    ErrorSignal.FromCurrentContext().Raise(ex); //ELMAH Signaling  (logs error but processing continues)
    return false;  //assuming the method returns a boolean value.
}
Advertisements

Written by Jim McMullen

May 5, 2011 at 3:18 pm

Posted in How-To

Tagged with , ,