5.4.4 Error Handling Statements

Error handling statements control the flow of execution when exception conditions occur.

 error-handling-statement = on-error-statement / resume-statement / error-statement 

Runtime Semantics

§ Each invocation of a VBA procedure has an error-handling policy which specifies how runtime errors SHOULD be handled.

§ When a procedure invocation is created, its error-handling policy is initially set to the Default policy, unless the procedure was directly invoked from the host application, in which case its error-handling policy is initially set to Terminate.

§ The possible values of a procedure’s error handling policy and the semantics of each policy are defined by the following table:

Policy Name

Runtime Semantics

Default

Discard the current procedure activation returning the error object and control to the procedure activation that called the current procedure activation. Apply the calling procedures activations error handling policy.

Resume Next

Continue execution within the same procedure activation with the <statement> that in normal execution order would be executed immediately after the <statement> whose execution caused the error to be raised.

Goto

Set the current procedure activation’s error handling policy to Default. Record as part of the procedure activation the identity of the <statement> whose execution caused the error to be raised. This is called the fault statement, and the error which caused the fault is called the active error. The execution continues in the current procedure starting at the current procedure activation’s handler label.

Retry

Continue execution within the same procedure activation starting with the <statement> whose execution caused the error to be raised and clear the active error.

Ignore

Use the Error data value of the current error object as the value of the expression in the current procedure activation whose execution caused the error to be raised. Continue execution as if no error had been raised and clear the active error.

Terminate

Perform implementation defined error reporting actions terminate execution of the VBA statements. Whether or not and how execution control is returned to the host application is implementation specific.