Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP Fortran 90 Programmer's Reference: HP Series 700/800 Computers > Appendix D Using the ON statement

Overview of how to handle arithmetic errors

» 

Technical documentation

» Feedback
Content starts here

 » Table of Contents

 » Glossary

 » Index

Error conditions detected by various HP Fortran 90 library routines result in basic arithmetic errors. For example, attempting to take the log (DLOG) of a negative number results in an error condition. When an error occurs, the action taken depends on the following:

  • What traps you have enabled (possibly with the +FP compile-line option; see Chapter 13 for information about this option).

  • Whether you have compiled with the +fp_exception option (see Chapter 13).

  • Whether you have replaced the matherr function with your own version. (For more information about matherr and how this might occur, see the HP-UX Floating-Point Guide.)

  • Whether you have used the ON statement to specify an action.

The following sections describe how to use the ON statement to specify the action you want to take in the event of an error.

Terminating program execution

Use the ABORT form of the CALL statement to terminate the program when an error occurs. In the following example, the log is taken of a negative number. The ABORT clause causes the program immediately after the error is detected:

PROGRAM MAIN
REAL :: x, y
ON REAL INEXACT ABORT
x = -10.0
y = LOG(x)
PRINT *, y
END

Ignoring errors

You can use the ON statement to ignore the error condition, as in the following:

PROGRAM main
REAL :: x, y
ON REAL INEXACT IGNORE
x = -10.0
y = log(x)
PRINT *, y
END

Note that, when you run this program, LOG still returns a NaN.

Calling a trap procedure

You can use the ON statement to call your own trap-handler procedure, as in the following:

PROGRAM MAIN
REAL(4) :: x, y
ON REAL INEXACT CALL trap
x = -10.0
y = LOG(x)
PRINT *, y
END
 
SUBROUTINE trap(n)
REAL(4) n
n = 99.87
END

When you run this program, it produces the following output:

99.87

Upon exit from a trap procedure, control returns to the instruction following the one that activated the trap, regardless of whether erring instruction appears in user code or in a library routine.

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© 1996 Hewlett-Packard Development Company, L.P.