Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


"On error" in ASP

Posted on 1999-09-29
Medium Priority
Last Modified: 2013-12-25
Can some please give me an example (code) of using the "on error" statement in ASP

What I want is an email sent to me if an error accurs anywhere on the page. I know how to send an email using ASPMail (or ASPEmail) but how do I trigger the email being sent??
Question by:adinas
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 25

Accepted Solution

clockwatcher earned 400 total points
ID: 2086292
It's kind of limited in VBScript since you can only use Resume Next, but here's a sample.

sub error_handler(myError, errorCount, errorString)    
  errorCount = errorCount + 1
  errorString = errorString &  "I ran into error #" & myError.number & "-- " & myError.description & "<BR>"
end sub


on error resume next

myErrCount = 0
myErrString = ""

for i = 1 to 10
  d1 = int(rnd * 10)
  d2 = int(rnd * 7)
  response.write d1 & "/" & d2 & " = " 
  response.write d1/d2
  response.write "<BR>"
  if err.number <> 0 then error_handler err, myErrCount, myErrString
<% if myErrCount > 0 then %>
I ran into the following errors: <BR>
<% response.write myErrString
else %>
I didn't hit any errors.
<% end if %>


The problem with resume next is that you kind of have to know where your errors may occur so that you can test the err object.  In most cases, it's fairly obvious which lines are going to cause problems, so it isn't usually that big of a deal to check the Err object.

If you're using ADO, then you should use your Connection's Error collection to pull your errors.  Make a database call, and then check your Errors collection to see if anything went wrong.  If you're not using ADO, just ignore those last comments.

Author Comment

ID: 2097060
Thanks for the answer its working perfectly.

But what if I do want the page to STOP proccessing but I still want the email sent to me? Is there a variation to the "on error resume next" command?

Author Comment

ID: 10852221
What you can do is redirect the user to a standard error page you create when an error happens. something like "Sorry, an error has occurred in the application...". If its for debugging, you will just have to comment the "on error" line when in debugging.

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
Suggested Courses

664 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question