5.4.4 Error Handling Statements
Note
This section describes the implementation of MS-VBAL §5.4.4 Error Handling Statements.
Each error-handling statement is listed below with the node the parser produces for it, the instruction kind it lowers to, and the RD-VBAL page that describes its implementation.
| Statement | AST node | Instruction kind | RD-VBAL |
|---|---|---|---|
On Error GoTo <label> |
OnErrorGoToStatementNode | OnErrorGoTo |
RD-VBAL §5.4.4.1 On Error Statement |
On Error GoTo 0, On Error GoTo -1 |
OnErrorGoToStatementNode |
OnErrorDisable |
RD-VBAL §5.4.4.1 On Error Statement |
On Error Resume Next |
OnErrorResumeStatementNode | OnErrorResumeNext |
RD-VBAL §5.4.4.1 On Error Statement |
Bare Resume, Resume 0 |
ResumeStatementNode | ResumeCurrentStatement |
RD-VBAL §5.4.4.2 Resume Statement |
Resume <label> |
ResumeStatementNode |
ResumeLabel |
RD-VBAL §5.4.4.2 Resume Statement |
Resume Next |
ResumeNextStatementNode | ResumeNext |
RD-VBAL §5.4.4.2 Resume Statement |
Error <number> |
ErrorStatementNode | RaiseError |
RD-VBAL §5.4.4.3 Error Statement |
Error interception
On Error and Resume work by interception, not by dedicated per-error branch logic. Every executor dispatch that
can yield an error routes it through ProcedureExecutor.InterceptError, which applies the activation's
error-handling policy. See RD-VBAL §3.5.4 Execution.
Each activation carries a single ErrorHandlerState: the error-handling mode, the handler target, the active error, and the fault-statement offset. The error-handling modes are described in RD-VBAL §5.4.4.1 On Error Statement.
Unhandled errors
An error that no handler catches propagates out of the activation; see
RD-VBAL §5.4.4.1 On Error Statement. Break mode is entered when an
unhandled run-time error has occurred; see RD-VBAL §2.3.2 Mode / State.
The Err object
VBA source reads and calls the error object at run time (Err.Number, Err.Raise 5): every error that is raised, handled or not, reaches the session's
error state, which is what Err reports (RD-VBAL §6.1.3.2 Err Class).
The Err class is described in RD-VBAL §6.1.3.2 Err Class.
⏮️ RD-VBAL §5.4.3.9 Set Statement | ⏭️ RD-VBAL §5.4.4.1 On Error Statement