Error Statement

Description

Simulates the occurrence of an error.

Syntax

Error errornumber

The errornumber can be any valid error number.

Remarks

If errornumber is defined, the Error statement simulates the occurrence of that error; that is, it sets the value of Err to errornumber.

To define your own error numbers, use a number greater than any of the standard error numbers. To avoid conflict with existing error numbers, create user-defined errors by defining your first error at 65,535 and work down from there.

If an Error statement is executed when no error-handling routine is enabled, an error message is displayed and execution stops. If the Error statement specifies an error number that is not used, an error message is displayed.

See Also

Err Function, Error Function, On Error Statement, Resume Statement.

Example

This example uses the Error statement to simulate error 11.


On Error Resume Next    ' Enable error handling.
Error 11    ' Simulate the "Division by zero" error.