Exceptions Best Practice

G

Guest

asp.net 2.0 vs2005

What is best practice for exception handling on a website in vs2005?
I was going to catch errors in application on_error event, log them to the
event log, then send users to an error page. But looking at the event log,
asp.net 2.0 logs those errors anyways, with more detail than i cen get from
the exception object. So is there any point logging them to the event log, is
it jsut better to let .net do this and get the more information, and jsut
have the 0n_error event handler re-direct to the custom error page?
Jsut wondering what other people do?
 
D

Dave Bush

I normally redirect to an aspx page in the onerror handler and then have
the aspx page send me an email with the error information. That way, 1) I
am aware that there was a problem and 2) the error "logging" is less
likely to fail due to environmental issues.

I don't normally have easy access to the server. In your case, I might
reduce it to just sending an email notifying me that there was an error
until you find that you need more information.

-----Original Message-----
From: Billy [mailto:[email protected]]
Posted At: Saturday, November 03, 2007 6:11 AM
Posted To: microsoft.public.dotnet.framework.aspnet
Conversation: Exceptions Best Practice
Subject: Exceptions Best Practice

asp.net 2.0 vs2005

What is best practice for exception handling on a website in vs2005?
I was going to catch errors in application on_error event, log them to the
event log, then send users to an error page. But looking at the event log,
asp.net 2.0 logs those errors anyways, with more detail than i cen get
from
the exception object. So is there any point logging them to the event log,
is
it jsut better to let .net do this and get the more information, and jsut
have the 0n_error event handler re-direct to the custom error page?
Jsut wondering what other people do?
 
M

Michael Nemtsev, MVP

Hello Billy,

read there http://msdn2.microsoft.com/en-us/library/aa479319.aspx

---
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo


B> asp.net 2.0 vs2005
B>
B> What is best practice for exception handling on a website in vs2005?
B> I was going to catch errors in application on_error event, log them
B> to the
B> event log, then send users to an error page. But looking at the event
B> log,
B> asp.net 2.0 logs those errors anyways, with more detail than i cen
B> get from
B> the exception object. So is there any point logging them to the event
B> log, is
B> it jsut better to let .net do this and get the more information, and
B> jsut
B> have the 0n_error event handler re-direct to the custom error page?
B> Jsut wondering what other people do?
 
D

derhamfamily

So is there any point logging them to the event log

We had some third party guys develop an asp.net app which logged
errors in the event log and to be honest, it's a nightmare because you
can't always get onto the server to view it.

I would highly recommend using log4net - it's free and really is very
easy to get it up and running yet powerful enough to enable you to get
many levels of logging and info out of your app. See
http://www.designforge.com/df/design/log4net.htm for a very simple way
of getting going with it (it works for both .net 2.0 and 1.1).
 
S

sloan

the enterpriselibrary.logging (.database) is an option
log4net is another.


I define one class with a static method that I encapsulate what I need
(logging, etc).

then either the use can get the error, or do a redirect.

If the exception is a unique constraint issue (SSN for example), then
showing them the issue on the same page is good I think.
If its a db is gone type error, then a redirect to a page is good.


public class ThisApplicationExceptionThinger

public static LogException (Page p , Exception ex , bool redirect )
{
//do something with the error, like the EnterpriseLibrary.Logging

if(redirect)
{
p.Response.Redirect("~/showexceptiontouser.aspx");
}

}

Something like that.
You can either querystring the msg or put it in the Session temporary.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,538
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top