HP Pascal/iX Reference Manual (31502-90022)

11- 21
* The run-time environment is restored to the environment of the
most recent TRY-RECOVER statement. This may involve prematurely
exiting any nested procedure and function calls and closing any
open files local to those routines.
* Execution is transferred to the statement following the reserved
word RECOVER.
If no errors are detected within the body of the TRY-RECOVER statement,
the recover statement is skipped, and execution continues at the first
statement following the TRY-RECOVER statement.
The TRY-RECOVER statement does not trap errors in its recover part (the
statement following the reserved word RECOVER). If an error occurs in the
execution of the recover part, execution is transferred to the recover
part of an enclosing TRY-RECOVER statement. If there is no enclosing
TRY-RECOVER statement the program aborts.
The semantics of the TRY-RECOVER statement do not guarantee that the
effects of any statements executed in the body of the TRY are valid when
executing the RECOVER statement. Certain implementations, however, may
guarantee that the effects of any executed statements are valid. Certain
other implementations may provide the user with a method of indicating
that certain variables preserve their value. See the
HP Pascal/iX
Programmer's Guide
or the
HP Pascal/HP-UX Programmer's Guide
, depending
on your implementation, for more details. Also see the compiler option
"VOLATILE" .
Note that when execution is transferred to the RECOVER statement, the
environment in which the error occurred no longer exists. If that
environment is required to perform error handling, then trap handlers are
required. See the chapter on Error Recovery in the
HP Pascal/iX
Programmer's Guide
or in the
HP Pascal/HP-UX Programmer's Guide
,
depending on your implementation, for more information.
Example
TRY
open( f, 'filename' );
RECOVER BEGIN
writeln( 'open failed' );
...
END;
The above code fragment prevents a program from aborting if a file cannot
be opened.
Example
PROCEDURE proc1;
BEGIN
... { errors will be trapped in try 0 }
TRY {try 1}
... { errors will be trapped here in try 1 }
RECOVER BEGIN
... { errors will be trapped in try 0 }
END;
... { errors will be trapped in try 0 }
END;
...
BEGIN
... { errors will abort the program }
TRY {try 0}
... { errors will be trapped here in try 0 }
proc1;
... { errors will be trapped here in try 0 }
RECOVER BEGIN
... { errors will abort the program }
END;
... { errors will abort the program }