LOTUSSCRIPT LANGUAGE
Example 1
When the sub DemoErr is called, the values of Error(), Err(), and Erl() are assumed to be the empty string (""), 0, and 0 respectively. The occurrence of an error resets them. Completing the associated error-handling routine resets them to the initial values.
Sub DemoErr ' Show values on entry to sub DemoErr. Print "Error: " Error(), " Err:" Err(), " Erl:" Erl() ' Designate an error-handling routine; then ' create an error. On Error GoTo ShowErr Error 11 ' This is line 10. ' Come here after Resume. Print "Error: " Error(), " Err:" Err(), " Erl:" Erl() Exit Sub ShowErr: ' Display the values on entry to the ' error-handling routine. Print "Error: " Error(), " Err:" Err(), " Erl:" Erl() Resume Next End Sub Call DemoErr() ' Output: ' Error: Err: 0 Erl: 0 ' Error: Division by zero Err: 11 Erl: 10 ' Error: Err: 0 Erl: 0
Example 2
This example shows the flow of control and the change in the values of the control variables Error, Err, and Erl during error processing. Though it will run and behave exactly as shown here, this is an artificial script. It is written to demonstrate these error-processing features.
' This example omits the Exit Sub statement of the preceding ' example. As a result, execution continues on to the ' error-handling routine. Sub ShowErr On Error GoTo CheckErr Error 150 ' This is line 5. Print "Error was handled... Error, Err, Erl are now:" Print Error(), Err(), Erl() ' This is line 7. ' Exit Sub statement was dropped here. CheckErr: Print Error(), Err(), Erl() Resume Next ' This is line 11. End Sub Call ShowErr() Print "Back from call of ShowErr"
After error 150 occurs at line 5, the error-handling routine at CheckErr prints this line:
Cannot find module %s 150 5
After the Resume statement, the Print statements in lines 6 and 7 prints these two lines:
Error was handled... Error, Err, Erl are now: 0 0
Execution continues on normally to the Print statement at CheckErr, which prints the following line:
0 0
Execution then continues normally to the Resume Next statement on line 11. Since there is no current error, there is no "Next" statement, so the Resume statement itself is invalid and generates an error, which becomes the current error; and the error-handling routine at CheckErr is invoked again. It prints the following line:
RESUME without error 20 11
The error-handling routine ends with the statement Resume Next. The "next" statement is End Sub. So the sub exits normally, and the Print statement after the sub call prints the following line:
Back from call of ShowErr
Example 3
An Err statement is placed at the beginning of the error-handling routine shown in the preceding example. The result is to invalidate the value of Erl: it no longer describes the error specified by Err.
Sub ShowErr On Error GoTo CheckErr Error 150 ' This is line 3. Print "Error was handled... Error, Err, Erl are now:" Print Error(), Err(), Erl() ' This is line 5. CheckErr: ' Reset the error number, without creating an error. Err 151 Print Error(), Err(), Erl() Resume Next ' This is line 10. End Sub Call ShowErr() Print "Back from call of ShowErr"
After error 150 occurs at line 3, the error-handling routine starting at CheckErr executes. It first sets the error number (the value of Err) to 151. This resets the Error function also (but not the Erl function). So the Print statement prints the following line:
Cannot find external name 151 3
After the Resume statement, the Print statements on lines 4 and 5 print these two lines:
Execution continues normally to the statements starting at CheckErr. The Err statement there resets the error number, and the Print statement therefore prints the following line. (Note that there is no current error, and therefore the value of Erl is still 0.)
Cannot find external name 151 0
The next statement executed, Resume Next, is invalid because there is no current error. So it generates an error, and the error-handling routine beginning at CheckErr is invoked again. It first sets Err to 151, and then prints the following line. (The values of Error and Err represent the latest assignment to Err; but Erl is still 10 because the current error occurred at line 10.)
Cannot find external name 151 10
The error-handling routine ends with the statement Resume Next. The "Next" statement is End Sub. So the sub exits normally, and the Print statement after the sub call prints the following line:
See Also