6.1.3.2 Err Class
Note
This section describes the implementation of MS-VBAL §6.1.3.2 Err Class.
The Err class is represented in the SDK by the interface
IStdErrClass. RD-VBA names the class ErrObject.
ErrObject is implemented in full: the RDCore.Runtime class ErrObject implements every member of IStdErrClass.
The Err function
🎯 The error object has two shapes. RD-VBA deliberately implements the MS-VBA one:
| Shape | Described by | The error object is |
|---|---|---|
| Global class module | MS-VBAL | The default instance of a global class module named Err. |
| Function | MS-VBA | An instance of a class named ErrObject, returned by Err: a zero-argument Function of the Information module. |
The two shapes are indistinguishable from source. A standard module's members are promoted to the project scope, so a
bare Err yields the error object in either shape
(RD-VBAL §2.3.1.3 Name Resolution).
RD-VBA's Err is a zero-argument Function of the Information module, returning an ErrObject
(RD-VBAL §6.1.2.7.1.15 Err). It is not a global class module with a
default instance, the shape MS-VBAL describes.
The MS-VBA shape leaves ErrObject nameable in an As clause, instead of shadowed by its own default instance.
Note
Not implemented. VBA source cannot read or call the error object at run time (Err.Number,
Err.Raise(...)), for two reasons:
- The
Errfunction of theInformationmodule has no runtime implementation: calling it raises the run-time error "Application-defined or object-defined error". - Calling a member of an object through a member access is not implemented: a member access reads only a field
of a class instance, and any other member reports
InternalError.
6.1.3.2.1 Public Subroutines
Note
This section describes the implementation of MS-VBAL §6.1.3.2.1 Public Subroutines.
| § | Member | Notes |
|---|---|---|
| 6.1.3.2.1.1 | Clear | |
| 6.1.3.2.1.2 | Raise | Raises an application error. See RD-VBAL §2.6.3 Runtime Errors. |
6.1.3.2.2 Public Properties
Note
This section describes the implementation of MS-VBAL §6.1.3.2.2 Public Properties.
StackTrace is not an MS-VBAL member. It is numbered after the last MS-VBAL member of this section.
| § | Member | Notes |
|---|---|---|
| 6.1.3.2.2.1 | Description | |
| 6.1.3.2.2.2 | HelpContext | |
| 6.1.3.2.2.3 | HelpFile | |
| 6.1.3.2.2.4 | LastDllError | |
| 6.1.3.2.2.5 | Number | |
| 6.1.3.2.2.6 | Source | See §6.1.3.2.2.6. |
| 6.1.3.2.2.7 | 🧩 StackTrace |
RD-VBA addition. See §6.1.3.2.2.7. |
6.1.3.2.2.6 Source
Note
This section describes the implementation of MS-VBAL §6.1.3.2.2.6 Source.
Err.Source defaults to the project name (MS-VBAL §6.1.3.2.2.6). The default is applied where a run-time error is
reported to the host: when the error's source is empty, the rdcore/session/execute result reports the project name
as the error's source (RD-VBAL §2.0.2 Client/Server Capabilities).
The session's own Source
(ISessionErrorState.Source) is empty until
the error object sets it (IStdErrClass.Source, or IStdErrClass.Raise with a source argument). VBA source cannot
reach the error object (see the note under The Err function), so the rdcore/session/execute
result always reports the project name as the error's source.
6.1.3.2.2.7 StackTrace
🧩 ErrObject.StackTrace is an RD-VBA addition to the MS-VBAL Err class, and the only member RD-VBA adds to it.
The MS-VBA error object identifies what an error was, not the call chain it was raised in. StackTrace reports that
call chain.
StackTrace is a read-only property. It lists the activations of the call stack the current error was raised on,
innermost activation first.
Runtime Semantics
The stack trace is captured when the error is raised, rather than derived when it is read, because by the time a handler reads it the activations it names have been unwound. It is captured at the interpreter's error-interception point, the one place every run-time error passes through (RD-VBAL §3.5.4 Execution).
Only the activation the error was raised in carries a location. A caller's activation record does not say where in itself it is suspended.
| Condition | StackTrace |
|---|---|
| No error is current. | Empty. |
An error was made current by setting Number, rather than by raising one. |
Empty. |
Implementation
ErrObject.StackTrace is implemented through the
VBStackTrace type. The current error's stack trace is held on
ISessionErrorState.StackTrace, and is built from
ICallStack.Frames.
⏮️ RD-VBAL §6.1.3.1 Collection Object | ⏭️ RD-VBAL §6.1.3.3 Global Class