On Error
The On Error statement allows you to create an error
handler that will trap all runtime errors. This doesn't catch
compile errors which occur before your script even begins
running.
The most common form of this statement is On Error Resume Next
which tells the script engine to Not throw an error and procede
to the next statement. You can detect if the previous line has thrown
an error by checking the Err.Number property.
For instance, if you do a mathematical calculation that results
in a divide-by-zero error, this can be caught by an On Error
handler. Also, any type of database query error that occurs when
using the ADO library can be caught because it is considered a
runtime error.
Const ZERO = 0 Dim fVar
On Error Resume Next fVar = 10.0 / ZERO If Err.Number <> 0 Then Response.Write "Error Occurred in fVar Calculation: " & Err.Description Response.Write "Error Number: " & Err.Number End If On Error Goto 0
As you can see in the sample code above, you terminate the error
handler with the statement On Error Goto 0. This special
command tells the script engine to resume normal error handling
processing.
|
 |

|