On Error Instruction

Syntax

On Error GoTo 0
-or-
On Error GoTo label
-or-
On Error Resume Next

Group

Error Handling

Description

Form 1: Disable the error handler (default).

Form 2: Send error conditions to an error handler.

Form 3: Error conditions continue execution at the next statement.

On Error sets or disables the error handler. Each user defined procedure has its own error handler. The default is to terminate the macro on any error. The Err object's properties are set whenever an error occurs. Once an error has occurred and the error handler is executing any further errors will terminate the macro, unless the Err object has been cleared.

Note: This instruction clears the Err and sets Error$ to null.

Example

Sub Main
On Error Resume Next
Err
.Raise 1
Debug
.Print "RESUMING, Err=";Err
On Error GoTo X
Err
.Raise 1
Exit
Sub

X: Debug.Print "Err=";Err
Err
.Clear
Debug
.Print "Err=";Err
Resume
Next
End
Sub