Err Statement

Description

Sets Err to a specific value.

Syntax

Err = errornumber

The errornumber argument can be any valid error number or 0, which means no run-time error occurred.

Remarks

Err is used to record whether a run-time error has occurred and identifies the error. Use the Err statement to set Err to a nonzero, whole number to communicate error information between procedures. For example, you might use one of the unassigned run-time error numbers as an application-specific error number. To determine which error numbers are being used, use the Error function, the Error statement, or both. To avoid conflict with existing error numbers, create user-defined errors by defining your first error at 65,535 and work down from there.

You can also set Err to 0 using any form of the Resume or On Error statement or by executing an Exit Sub, Exit Function or Exit Property statement within an error handler. In addition, the Error statement can set Err to any value to simulate any run-time error.

See Also

Err Function, Error Function, Error Statement.

Example

This example shows how the Err statement is used to clear an error by setting Err to 0. Error number 55 is generated to illustrate its usage.


On Error Resume Next    ' Enable error handling.
Open "TESTFILE" For Output as #1    ' Open file for output.
Kill "TESTFILE"    ' Attempt to delete open file.
Select Case Err    ' Evaluate Error Number.
    Case 55    ' "File already open" error.
        Close #1    ' Close open file.
        Kill "TESTFILE"    ' Delete file.
        Err = 0    ' Reset Err to 0.
    Case Else
        ' Handle other situations here... 
End Select