HP Pascal/iX Programmer's Guide (31502-90023)

11- 3
1. The subsystem in which the error occurred (the program, a library,
or the operating system) calls the predefined procedure
escape
with
error_code
as its parameter. The parameter
error_code
is an
integer expression whose value represents the error.
2. The procedure
escape
sets
error_code
and saves it.
3. The program's run-time environment reverts to that of the program
unit (main program, procedure, or function) that contains the
TRY-RECOVER construct.
4. The program executes the
statement
of the RECOVER part (skipping
any
statement
s between the
statement
where the error occurred and
the RECOVER's
statement
).
If no
statement
causes an error, the program skips the RECOVER's
statement
and executes the statement that follows the TRY-RECOVER
construct.
Example 1
PROGRAM prog (input,output);
$STANDARD_LEVEL 'HP_MODCAL'$
VAR
i,j,k,l : integer;
PROCEDURE proc;
BEGIN
i := 0;
j := 0;
k := 0;
END;
BEGIN
TRY
read(i); {Error here transfers control to proc.}
read(j); {Executed only if no error occurs for read(i).
Error here transfers control to proc.}
read(k); {Executed only if no error occurs for read(i) or read(j).
Error here transfers control to proc.}
RECOVER
proc; {Executed only if an error occurs
for read(i), read(j), or read(k).}
l := i+j+k; {Always executed.}
END.
If the RECOVER's
statement
is empty, the person who is running the
program will not know when the TRY-RECOVER construct has handled an
error.
If an error occurs when the program executes the RECOVER's
statement
, the
program aborts--unless the TRY-RECOVER construct is within another
TRY-RECOVER construct. In that case, the program executes the RECOVER
statement
of the outer TRY-RECOVER construct.
Example 2
PROGRAM prog (input,output);
$STANDARD_LEVEL 'HP_MODCAL'$
VAR
i,j : integer;
iok : Boolean;
PROCEDURE newj;
BEGIN
writeln('That value is illegal.');
prompt('Please enter an integer for j:');
read(j);
END;
PROCEDURE newij;