Get Fresh Tips Every Week!
Don't Miss Any Web Development Tips. Subscribe to the Web Development Tip Newsletter.

View Archive

Bookmark This Site
Keep up with our Tips


Tip of the Day RSS Feed
Fresh Web Development Tips Daily


Business Solutions
Our tips are powerful.
Our writers are experts.
Our results are guaranteed.

 

Listen to our Radio Show
Hot topics for both consumers
and webmarketers
on WebmasterRadio.FM

Every Wednesday, 4PM Eastern.

 

Error handling in asp

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 <> 0 then response.redirect "yourerrorpage.asp?err=" & err.description
*note: use this redirect ONLY if you want to alert the user of the error. You can omit this if you simply want the user to continue without an error showing up. You will have to find out why the error happened, but that's out of scope with this tip.

After that offending line, write:
On Error Goto 0
-- this resets the error object.

On your error page, at the top (but within the <% %> 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.

5.6 5.6
Save Tip Tip Rating

Comments

Nobody has commented on this tip yet. Be the first.

Name:


Comment:




Learn more about our Exclusive Program we offer our clients.