November 6, 2009, Newsletter Issue #76: Error handling in asp

Tip of the Week

When your code bombs and displays a "Page can't be reached" or and other error page, it's embarrasing. Here's a more elegant way to handle it. Use "On Error Resume Next" and "On Error Goto 0" EFFECTIVELY. First create an error page yourself - one that not only looks better than the standard error page, but that also tells the user something usable.. and include a "go back" button if necessary.

To use the above, write:
On Error Resume Next
...on the line ABOVE where the error would possibly happen, for instance, just before a database call.


Then on the line immediately after the offending line, write:
If err.number code block) write:
response.write "Error: " & request.querystring("err") & " please contact your administrator, or to try again, click here" (originalpage.asp is the page you had the error).

Microsoft has a good resource on this topic.

About LifeTips

Now one of the top on-line publishers in the world, LifeTips offers tips to millions of monthly visitors. Our mission mission is to make your life smarter, better, faster and wiser. Expert writers earn dough for what they know. And exclusive sponsors in each niche topic help us make-it-all happen.

Not finding the advice and tips you need on this Web Development Tip Site? Request a Tip Now!


Guru Spotlight
Candi Wingate