Class VBApplicationErrorInfo
Encapsulates the serializable error data for an application error: a run-time error
workspace source raised for itself, with an Error statement
(MS-VBAL §5.4.4.3) or with Err.Raise (§6.1.3.2.1.2).
public record VBApplicationErrorInfo : VBErrorInfo, IEquatable<VBErrorInfo>, IVBRaisableError, IEquatable<VBApplicationErrorInfo>
- Inheritance
-
VBApplicationErrorInfo
- Implements
- Inherited Members
Remarks
🧩 Errors should be used to generate error diagnostics.
MS-VBAL does not distinguish this from an error the runtime semantics report — both are run-time
errors, both interrupt the activation, both reach Err, both may be caught. RD-VBAL
§2.6.3 does, in one respect: the diagnostic families differ, so the editor can say whether a
workspace raised its own error or tripped over one. The distinction is in who raised it and
nothing else — Err.Raise 11 is an application error, not a division-by-zero, even though
11 is a code MS-VBA defines.
Constructors
VBApplicationErrorInfo(int, SourceLocation, string, string)
Encapsulates the serializable error data for an application error: a run-time error
workspace source raised for itself, with an Error statement
(MS-VBAL §5.4.4.3) or with Err.Raise (§6.1.3.2.1.2).
public VBApplicationErrorInfo(int CustomErrorCode, SourceLocation Location, string Description, string Verbose)
Parameters
CustomErrorCodeintThe custom workspace application error code. MS-VBAL §6.1.3.2.1.2 reserves 0-512 for system errors and 513-65535 for user-defined ones.
LocationSourceLocationThe document location of what raised the error.
DescriptionstringThe error description. What
Err.Descriptionreports.VerbosestringA detailed description of the error.
Remarks
🧩 Errors should be used to generate error diagnostics.
MS-VBAL does not distinguish this from an error the runtime semantics report — both are run-time
errors, both interrupt the activation, both reach Err, both may be caught. RD-VBAL
§2.6.3 does, in one respect: the diagnostic families differ, so the editor can say whether a
workspace raised its own error or tripped over one. The distinction is in who raised it and
nothing else — Err.Raise 11 is an application error, not a division-by-zero, even though
11 is a code MS-VBA defines.
Properties
AsErrorInfo
This error as the diagnostic source metadata it is.
public VBErrorInfo AsErrorInfo { get; }
Property Value
Remarks
Every raisable error is a VBErrorInfo — that is the constraint C# has no way
to state on an interface, so it is stated here instead, and implemented as this. It is what
lets a carrier hold the interface, keeping the diagnostic family with the error, and still hand the
error to the diagnostics pipeline, which is generic over the record rather than over this.
CustomErrorCode
The custom workspace application error code. MS-VBAL §6.1.3.2.1.2 reserves 0-512 for system errors and 513-65535 for user-defined ones.
public int CustomErrorCode { get; init; }
Property Value
Methods
Raised(int, SourceLocation, string, string?)
Creates the error an Error statement or an Err.Raise generates.
public static VBApplicationErrorInfo Raised(int errorNumber, SourceLocation location, string verbose, string? description = null)
Parameters
errorNumberintThe error code the workspace raised.
locationSourceLocationThe document location of the
Errorstatement orErr.Raiseinvocation.verbosestringA detailed message that is optionally appended, depending on the current server trace configuration.
descriptionstringThe description the raiser supplied, or
nullto derive one fromerrorNumber.
Returns
Remarks
The description is the raiser's own when it supplied one. Unspecified, MS-VBAL
§6.1.3.2.1.2 says to use "the String that would be returned by the Error function" for
errorNumber, or "Application-defined or object-defined error" when it
corresponds to no VBA error — which is what GetErrorString(VBRuntimeErrorId) falls
back to.
ToDiagnosticCode()
The RD-VBAL §2.6.3 diagnostic code of this error, prefix and all.
public string ToDiagnosticCode()
Returns
Remarks
👉 A member rather than an extension, deliberately. An extension binds to the static type of what it is called on, so an application error held in a variable declared as anything more general would silently report the wrong family — which is exactly how an error travels through the interpreter.