Compiler Library/XL Reference Manual (32650-90029)

A- 3
abort = 1;
{This procedure returns a result of -999 and continues
the execution of the program if the SQRT routine has
the error. Otherwise, the program aborts.}
BEGIN
IF errornum = sqrt_errornum THEN BEGIN
result := sqrt_default;
took_trap := True;
quit := continue;
END
ELSE quit := abort;
END; {error}
{Start the main body of the program.}
BEGIN
{Set up the -1 value.}
x := -1.0;
Nan_var := sqrt(x);
took_trap := False;
{Arm the trap mechanism by calling XLIBTRAP.}
xlibtrap(waddress(error), oldplabel);
writeln ('Calling sqrt with NaN');
{Call sqrt with a negative value.}
x := sqrt(Nan_var);
if took_trap
then begin
x := result;
took_trap := False;
end;
writeln('X should be -999.0. X = ', x);
writeln('This should be the last line before an abort.');
{Call alog with a negative value.}
y := alog(Nan_var);
writeln('This line should NOT be printed');
END.
where
result = the result of the calculation that produced the
error. The library procedure determines the
size and type of the value returned to result.
If you know that only a subset of the possible
result types occurs in your program, the
extensive variant RECORD structure shown above
is not needed. You can change the value
returned to result in the library procedure and
have the change reflected in the code if
optimization is
not
being used.
errornum = the error number. (See the "Error Messages"
section in this appendix for a list of the
error messages.)
quit = a flag set by the user-written procedure error.
If quit equals zero, the trap returns to your
program without printing an error message. If
quit does not equal zero, your program is
aborted.