Reference Guide

RPL Programming 1-35
Making an Error Trap
You can construct an error trap with one of the following conditional structures:
IFERR … THEN … END.
IFERR … THEN … ELSE … END.
The IFERR  THEN  END Structure
The syntax for this structure is
«
IFERR
trap-clause
THEN
error-clause
END
»
The commands in the error-clause are executed only if an error is generated during execution of the trap-clause. If
an error occurs in the trap-clause, the error is ignored, the remainder of the trap-clause is skipped, and program
execution jumps to the error-clause. If no errors occur in the trap-clause, the error-clause is skipped and execution
resumes after the END command.
To enter IFERR  THEN  END in a program:
Press
!°LL %ERROR%
!%IFERR%
.
Example:
The following program takes any number of vectors or arrays from the stack and adds them to the
statistics matrix. However, the program stops with an error if a vector or array with a different number of columns
is encountered. In addition, if only vectors or arrays with the same number of columns are on the stack, the
program stops with an error after the last vector or array has been removed from the stack.
«
WHILE DUP TYPE 3 == REPEAT Σ+ END
»
In the following revised version, the program simply attempts to add the level 1 object to the statistics matrix until
an error occurs. Then, it ends by displaying the message
DONE
.
Program: Comments:
«
IFERR
Starts the trap-clause.
WHILE
1
REPEAT
Σ+
END
The WHILE structure repeats
indefinitely, adding the vectors
and arrays to the statistics matrix
until an error occurs.
THEN
"DONE" 1 DISP
1 FREEZE
Starts the error clause. If an error
occurs in the WHILE structure,
displays the message DONE in
the status area.
END
»
Ends the error structure.