Log error, then swallow it

25 views
Skip to first unread message

adamtoth

unread,
Feb 18, 2007, 9:11:28 PM2/18/07
to ELMAH
Sometimes I want to catch an exception, log it and notify an
administrator, but then swallow it and keep the user on the same web
page with an informative message about the failure, instead of letting
the exception bubble up and take them to the custom error page.

Since I am already using ELMAH as a storage mechanism for my unhandled
exceptions, is there a way to tap into it and use it to store some of
my "handled" exceptions that I care about keeping track of?

I've looked at creating my own instances of the ErrorLog and other
objects, but didn't see anything that let me use it that way.

Thanks,

Adam

Atif Aziz

unread,
Feb 19, 2007, 3:36:11 AM2/19/07
to el...@googlegroups.com
Check out the following the thread for the solution:

http://tinyurl.com/2a6teb

-or-

http://groups.google.com/group/elmah/browse_frm/thread/5c75b93558bfdac6


- Atif

scott wilson

unread,
Feb 19, 2007, 7:32:12 AM2/19/07
to el...@googlegroups.com
adamtoth wrote:
> Sometimes I want to catch an exception, log it and notify an
> administrator, but then swallow it and keep the user on the same web
> page with an informative message about the failure, instead of letting
> the exception bubble up and take them to the custom error page.
>
One thing that the other thread doesn't mention explicitly is that in
order to do this, you will need to manage everything within a try/catch
block on the page or control level.

ELMAH normally works by allowing the exception to bubble up to the
application level and working from there. At that point, however, it
will be impossible (or at least more difficult) to keep the user on the
same page.

Another thing that I should mention is that if you are expecting for
some exceptions to happen, then it's a lot more efficient for your app
to manage these possibilities before the actual exception happens. I
don't know exactly what exceptions you are swallowing, but for example,
let's say for example you were iterating through a recordset and
calculating some percentages. You'd be better off checking if the
denominator == 0 and writing a message than waiting to catch a
DivisionByZeroException and then writing the error message. It is still
possible to log an exception in ELMAH without being in a catch block.

-Scott


adamtoth

unread,
Feb 22, 2007, 12:24:38 PM2/22/07
to ELMAH
Thanks guys, that is just the ticket!

In my case, I am trying to handle things like timeouts (trying to talk
to AD, connect to sql server, or long running sql operations) that I
have to handle in Page_Error, log the exception so the dbas and help
desk folks can start troubleshooting what may be happening, and send
the user to an "Application is temporarily unavailable"-type page.

Adam

Reply all
Reply to author
Forward
0 new messages