The IFERR 7 THEN 7 ELSE 7 END Structure

The syntax for this structure is

«IFERR trap-clause

THEN error-clause ELSE normal-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, execution jumps to the normal-clause at the completion of the trap-clause.

To enter IFERR 7 THEN 7 ELSE 7 END in a program:

Press !°LL%ERROR% @%IFERR%

Example: The following program prompts for two numbers, then adds them. If only one number is supplied, the program displays an error message and prompts again.

Program:

Comments:

 

 

«

 

DO

Begins the main loop.

"KEY IN a AND b" " "

Prompts for two numbers.

INPUT OBJ→

 

UNTIL

Starts the loop test clause.

IFERR

The error trap contains only the +

+

command.

THEN

If an error occurs, recalls and displays the

ERRM 5 DISP

Too Few Arguments message for 2

2 WAIT

seconds, then puts 0 (false) on the stack for

0

the main loop.

 

ELSE

If no error occurs, puts 1 (true) on the stack

1

for the main loop.

END

Ends the error trap.

END

Ends the main loop. If the error trap left 0

 

(false) on the stack, the main loop repeats —

 

otherwise, the program ends.

»

 

 

 

1-36 RPL Programming