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 7 THEN 7 END Structure
The syntax for this structure is
«… IFERR
The commands in the
To enter IFERR 7 THEN 7 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 | |
WHILE | The WHILE structure repeats | |
1 | indefinitely, adding the vectors | |
REPEAT | and arrays to the statistics matrix | |
Σ+ | until an error occurs. | |
END | ||
| ||
THEN | Starts the error clause. If an error | |
"DONE" 1 DISP | occurs in the WHILE structure, | |
1 FREEZE | displays the message DONE in | |
| the status area. | |
END | Ends the error structure. | |
» |
|
RPL Programming