Using On Error Resume Next
Using On Error Resume Next
By Mike Prestwood
Posted 9 years ago on 11/15/2006 and updated 7/2/2008
Take Away: You can use "On Error Resume Next" to suppress errors and "On Error Goto
0" to stop suppressing errors.
Tags: ASP , On Error Resume Next , trap errors , CDO , send email
KB100411
ASP's ability to trap for errors is pretty weak compared to other languages. However, you
can trap for errors, suppress errors, and stop suppressing errors. When an error is found,
you can also handle it.
Suppressing Errors
To start trapping errors, add the following line:
On Error Resume Next
This will suppress all errors for the duration of the script. For example, normally the
following code would cause the death of your code with a division by error message:
Dim x
x = 1/0
Here is how to use On Error to selectively display the value of this variable but only when
FormatDateTime fails.
On Error Resume Next
Response.Write FormatDateTime(f_CurrentActualDate, vbShortDate)
If ErrNumber <> 0 Then
Break(f_CurrentActualDate)
End If
On Error Goto 0
x = 1/0
End Sub
")")
If Err.Number = 0 Then
If Counter = 1 Then
Response.Write("Email sent...")
Else
Response.Write("Email sent...
(Attempts needed: " & Counter &
End If
Counter = 10
Else
Counter = Counter + 1
If Counter => 10 Then
Resonse.Write("Email NOT sent (10 attempts failed). If important,
try again.")
End If
End If
WEnd
On Error GoTo 0