5.4.2.17 Exit Sub Statement
Note
This section describes the implementation of MS-VBAL §5.4.2.17 Exit Sub Statement.
Syntax
| AST node | Instruction kind | Notes |
|---|---|---|
KeywordStatementNode (Token: "Exit Sub") |
ExitProcedure |
No resolved target. |
Exit Sub, Exit Function and Exit Property all lower to the
InstructionKind ExitProcedure
(RD-VBAL §3.5.2 Instruction).
Static Semantics
An Exit Sub must be inside the body of a subroutine; in a Function or in a property it is
VBC09332 (ExitSubNotAllowedInFunctionOrProperty). The rule is
ExitStatementStaticSemantics's, applied when the kind of the procedure is known
(RD-VBAL §5.4.2.18 Exit Function Statement).
Runtime Semantics
The executor dispatches the ExitProcedure instruction, which completes the current activation.
Reaching the end of the instruction list completes the activation "as if execution had reached the end of the
body" (the wording of MS-VBAL §5.4.2.17). This is the same outcome as an explicit Exit
(RD-VBAL §3.5.4 Execution).
MS-VBAL §6.1.3.2.1 has Exit Sub, Exit Function and Exit Property clear Err. MS-VBA clears it as an
activation completes, by an Exit or by reaching the end of the body alike, and only from within an error handler — an
error On Error GoTo caught. An error On Error Resume Next went on past was handled by none, and is still Err when
the procedure returns; so is an error source set with Err.Number (recorded in Excel).
Implementation
RDCore.Runtime.Execution.ProcedureExecutordispatchesExitProcedureinstructions.
⏮️ RD-VBAL §5.4.2.16 On...GoSub Statement | ⏭️ RD-VBAL §5.4.2.18 Exit Function Statement