Compiler Library/XL Reference Manual (32650-90029)
A-2
(The HP FORTRAN 77/XL ON statement has additional options that
make it easier to use than XLIBTRAP. See the
HP FORTRAN 77/XL
Reference Manual
for more details.)
3. If a user-written error procedure has not been specified by using
XLIBTRAP or with the HP FORTRAN 77/XL ON statement and the trap is
not to be ignored, the appropriate error report is produced and
the current program is aborted. The library trap mechanism is
disarmed when the user-written procedure is called. If the
compiler finds an indication to ignore the trap, control is
immediately returned to the library procedure.
4. When the user-written error procedure returns control to the
library error handler, the library trap mechanism is rearmed.
5. As defined below, a user-written error procedure can either set a
result or a set a flag. The QUIT parameter in the example below
directs the library error handler to abort the current program or
to return control to the procedure that found the error.
A user-written error procedure (named error in this example) could be
declared as follows:
PROGRAM libtrap_test(output);
A Pascal Example Using XLIBTRAP
The following example shows a user-written HP Pascal error procedure to
be called whenever an error is detected.
{This program tests the ability to invoke library trap handling from Pascal.}
TYPE
word_int = integer;
plabel = word_int;
stack_array = ARRAY [1 .. 4] of word_int;
VAR
Nan_var, {Holds the value -1.}
x,y: REAL; {Used to hold results returned from the library routines.}
oldplabel : plabel;
result : real;
took_trap : Boolean;
{Declare the sqrt library routine.}
FUNCTION sqrt : REAL; INTRINSIC;
{Declare the alog library routine.}
FUNCTION alog : REAL; INTRINSIC;
{Declare XLIBTRAP.}
PROCEDURE xlibtrap; intrinsic;
{Provide the error routine.}
PROCEDURE error (VAR marker: stack_array;
VAR errornum,
VAR quit: word_int);
{Declare constants.}
CONST
sqrt_errornum = 10;
sqrt_default = -999.0;
continue = 0;