Examples: On Error statement

In this example, the On Error statement directs LotusScript® to continue execution at the next statement after any error that occurs while the function Best is running.

The Call statement generates a division-by-zero error at the attempted division of y by z. Execution resumes at the next statement, the If statement. The current error number is the value of the constant ErrDivisionByZero, which was defined in the file lserr.lss previously included in the script by the %Include statement. Therefore the Print statement is executed. Then the Exit Function statement terminates execution within Best(), without executing further statements within the procedure; and control returns to the caller.

%Include "lserr.lss"
Function Best()
   Dim x As Integer, y As Integer, z As Integer
   ' After any error-generating statement, resume
   ' execution with the next statement.
   On Error Resume Next
   ' ...
   y% = 3
   z% = 0
   ' ...
   x% = y% / z%  ' Generates division-by-zero error.
   If Err = ErrDivisionByZero Then
      Print "Attempt to divide by 0. Returning to caller."
      Exit Function
   End If
   ' ...
End Function
Call Best()