Best standard for error trapping?

V

VB Programmer

Should I wrap every function in a Try/Catch block? What is the standard for
ASP.NET?

Should I call 1 common error trapping routine which does a respons.write of
the error? What do you all do?

Thanks.
 
S

Scott Mitchell [MVP]

VB said:
Should I wrap every function in a Try/Catch block? What is the standard for
ASP.NET?

Not unless you expect that you can recover from the exception that is
thrown.

If the exception that is thrown is a "deal breaker," such as the
database being down, or whatnot, then what I usually do is the following:

-- Don't use a Try...Catch, but instead let the exception propogate up
to the ASP.NET application.

-- Write code in the Global.asax's Application_OnError to log
information about the error, email the administrator, etc.

-- Use the <customErrors> setting in Web.config to display a pretty
error page to the end user.


There are some tools to help with this process. First, check out the
Exception Management Application Block (EMAB):
http://aspnet.4guysfromrolla.com/articles/032404-1.aspx

Another approach is to use HTTP Handlers/Modules to basically take care
of all of the plubming for you. This is the technique I use in my
real-world apps, and there is an article I coauthored on a particular
implementation that you can download and plug into your Web apps:
http://tinyurl.com/47cp2

hth

--

Scott Mitchell
(e-mail address removed)
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!
 
V

VB Programmer

Excellent and informative response! Thanks!

Scott Mitchell said:
Not unless you expect that you can recover from the exception that is
thrown.

If the exception that is thrown is a "deal breaker," such as the database
being down, or whatnot, then what I usually do is the following:

-- Don't use a Try...Catch, but instead let the exception propogate up to
the ASP.NET application.

-- Write code in the Global.asax's Application_OnError to log information
about the error, email the administrator, etc.

-- Use the <customErrors> setting in Web.config to display a pretty error
page to the end user.


There are some tools to help with this process. First, check out the
Exception Management Application Block (EMAB):
http://aspnet.4guysfromrolla.com/articles/032404-1.aspx

Another approach is to use HTTP Handlers/Modules to basically take care of
all of the plubming for you. This is the technique I use in my real-world
apps, and there is an article I coauthored on a particular implementation
that you can download and plug into your Web apps:
http://tinyurl.com/47cp2

hth

--

Scott Mitchell
(e-mail address removed)
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top