LOTUSSCRIPT LANGUAGE


On Error statement
Example

Determines how an error will be handled in the current procedure.

Syntax

On Error [ errNumber ] { GoTo label | Resume Next | GoTo 0 }

Elements

errNumber


GoTo label
Resume Next
GoTo 0
Usage

The On Error statement is an executable statement. It allows the procedure containing it to change the way LotusScript responds to particular errors. If no On Error statement is used, an error ordinarily causes execution to end. On Error allows a procedure to handle the error and continue execution appropriately.

How does On Error work?

An On Error statement is in effect from the time the statement runs until superseded by another On Error statement or until control returns to the calling procedure:


For example, the following code sends error 11 to the DivBy0 label and all other errors to the General label:
If you reverse the statements, however, all errors go to the General label:
The following statements send error 11 to the General label:
How does the error-handling routine work?

An error-handling routine begins with a labeled statement. The routine ends when LotusScript encounters a Resume, Exit Sub, Exit Property, or Exit Function statement. If an error occurs in the error-handling routine, execution ends.

While the error-handling routine is running, the Err, Erl, and Error functions describe the error being handled. A Resume statement will reset these values.

Where are error numbers and messages defined?

LotusScript specifies a standard set of errors, and corresponding error numbers (as constants), in the file lserr.lss. To define these errors and their numbers, include this file (using %Include) in a script that you compile or load before running any other script. Then these error numbers can be used in On Error statements to control error handling in the session.

Use the Error statement to define new error numbers and messages.

Language cross-reference

@Error function in formula language

@IfError function in formula language

@Failure function in formula language

Example
See Also