Simulates the occurrence of an error.
Error errornumber
The errornumber can be any valid error number.
The Error statement is supported for backward compatibility. In new code, especially when creating OLE Automation objects, apply the Raise method to the Err object to generate run-time errors. Not all Visual Basic host applications can create OLE Automation objects. See your host application’s documentation to determine whether it can create classes and OLE Automation objects.
If errornumber is defined, the Error statement calls the error handler after filling the Err object’s properties with default values (as shown in the following table):
Property |
Value |
Number |
Value specified as argument to Error statement. Can be any valid error number. |
Source |
Name of the current Visual Basic project. |
Description |
A string expression corresponding to the return value of the Error function for the specified Number, if this string exists. If the string doesn’t exist, Description contains a zero-length string (""). |
HelpFile |
The fully qualified drive, path, and filename of the Visual Basic Help file. |
HelpContext |
The Visual Basic Help file context ID for the error corresponding to the Number property. |
If no error handler exists or if none is enabled, an error message is created and displayed from the Err object properties.
Clear Method, Err Object, Error Function, On Error Statement, Raise Method, Resume Statement.
This example uses the Error statement to simulate error number 11.
On Error Resume Next ' Defer error handling.11 ' Simulate the "Division by zero" error.