Practical Standards for Microsoft Visual Basic .NET (Pro-Developer)

[Previous] [Next]

Before you can write effective error-handling code, you must understand Visual Basic's Err object, a run-time object that contains information about the most recent error. The properties of the Err object are populated when an error is encountered at run time or when you deliberately raise an error using the Raise method of the Err object.

The property values of the Err object are cleared when an On Error statement (such as On Error Resume Next ) is encountered and after a procedure is exited via an Exit Sub , Exit Function , or Exit Property statement. To explicitly clear the Err object, you invoke its Clear method. The table below lists the properties of the Err object.

Property Description
Number The unique number that identifies the error.
Source Name of the current Visual Basic project.
Description A descriptive error message. If no such string exists for an error, the description says "Application-defined or object-defined error."
HelpFile The drive, path , and filename of the Visual Basic Help file related to the error.
HelpContext The Visual Basic Help file context ID for the error.
LastDLLError On 32-bit Microsoft Windows operating systems, the system error code for the last call to a dynamic-link library (DLL). The LastDLLError property is read-only.

NOTE


When an error is raised, the Err object's properties are set to the appropriate values for the error. If you need to use any of these values, you should act on them immediately or store them in a variable before taking any other action because the Err object's property values might be reset. Also, the property values in the Err object reflect only the most recent error; the Err object does not maintain an error history list.

Категории