473,387 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Best standard for error trapping?

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.
Nov 18 '05 #1
2 1038
VB Programmer wrote:
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
mi******@4guysfromrolla.com
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!
Nov 18 '05 #2
Excellent and informative response! Thanks!

"Scott Mitchell [MVP]" <mi******@4guysfromrolla.com> wrote in message
news:l_*****************@newssvr14.news.prodigy.co m...
VB Programmer wrote:
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
mi******@4guysfromrolla.com
http://www.4GuysFromRolla.com

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

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: deko | last post by:
I use this convention frequently: Exit_Here: Exit Sub HandleErr: Select Case Err.Number Case 3163 Resume Next Case 3376 Resume Next
9
by: Robert Wing | last post by:
I support an MS Access application in which errors are trapped using the On Error statement. Just recently, the users of this system have experienced run-time error number 3021 on a random basis. ...
2
by: Steve Richfield | last post by:
My error handler works GREAT. However, VBA seems to have some bugs/features that are causing it fits. The little snippet that I put at the end of each routine looks like this: Error_Handler: If...
3
by: Nathan Bloomfield | last post by:
Hi there, I am having difficulty with a piece of code which would work wonders for my application if only the error trapping worked properly. Basically, it works as follows: - adds records...
13
by: Thelma Lubkin | last post by:
I use code extensively; I probably overuse it. But I've been using error trapping very sparingly, and now I've been trapped by that. A form that works for me on the system I'm using, apparently...
3
by: Smriti Dev | last post by:
Hi There, I have the following code and when I try to run it, I get a type mismatch error. I would really appreciate your help with this. Thanks kindly, smriti --- Private Sub cmdOK_Click()
2
by: Captain Nemo | last post by:
I'm still using Office 2000 myself, but some of my clients have Office 2003. I've recently added a piece of code to create an instance of Word, open a document, fill in the blanks and become...
9
by: 47computers | last post by:
Pretty new to PHP, I recently started learning about error trapping. As of right now, I include the following into a page in my website: -------BEGIN PASTE-------- error_reporting(E_ERROR |...
1
by: Elmo Watson | last post by:
Up until now, I've done all the work (gui/front end programming, classes, etc) I've done all my error trapping (try/catch) in the methods in the code behind. Now I've got an opportunity to do...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.