The IFERR THEN ELSE END Structure

The syntax for this structure is

«IFERR trapclause

THEN errorclause ELSE normalclause END »

The commands in the errorclause are executed only if an error is generated during execution of the trapclause. If an error occurs in the trapclause, the error is ig nored, the remainder of the trapclause is skipped, and program execution jumps to the errorclause. If no errors o ccur in the trapclause, execution jumps to the nor malclause at the completion of the trapclause.

To enter IFERR THEN ELSE 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.

»

 

 

 

136 RPL Programming

Page 60
Image 60
HP 50g Graphing manual Iferr then Else END Structure, To enter Iferr then Else END in a program, Press !LL %ERROR% @%IFERR%