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

11- 1
Chapter 11 Error Recovery and Debugging
There are three types of Pascal errors. They are:
* An
error
, which violates the definition of the HP Pascal language.
* A
compile-time error
, which occurs when you compile your program
(as in the case of a syntax error).
* A
run-time
error, which occurs when you run your program (as in
the case of a value out of range).
Errors are not to be confused with notes and warnings, both of which
occur at compile time. A
note
gives you information that may help you
make your program more efficient. A
warning
alerts you to a situation
that could cause a run-time error (the compiler cannot tell if it will).
This chapter explains:
* How to write error recovery code for your program, so that it can
handle run-time errors that would otherwise cause it to abort
(error recovery code does not catch compile-time errors, warnings,
or notes).
* How to use the MPE/iX traps that you can use with HP Pascal.
* How to compile your program for use with the HP TOOLSET/XL
debugger, the HP Symbolic Debugger, or the system debuggers.
Error Recovery
The system programming extensions that support error recovery are the
predefined procedure
escape,
the predefined function
escapecode,
and the
TRY-RECOVER construct. They are interdependent. A typical TRY-RECOVER
construct has the form:
TRY
statement;
{statement;}
.
.
.
RECOVER
BEGIN {error-handling code}
temp := escapecode; {save escapecode value, which can change}
CASE temp OF {handle error}
{handle expected values of temp here}
OTHERWISE
escape(temp); {cannot handle this error here;
pass to any enclosing TRY-RECOVER construct}
END; {CASE}
END; {error-handling code}
Escape Procedure
The predefined procedure
escape
is called by your program, a library
routine, or the operating system when a run-time error occurs. If a
TRY-RECOVER construct is active when the system calls
escape
, the program
executes the
statement
associated with the RECOVER part (see "TRY-RECOVER
Construct" ). If no TRY-RECOVER construct is active, the program
aborts. A TRY-RECOVER construct is active if the TRY statement has been
executed, but the RECOVER statement has not.