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!