Example 17
PROGRAM main
!$HP$ CHECK_OVERFLOW INTEGER ON
INTEGER :: i ON INTEGER OVERFLOW CALL trap_oflow
!assign to i the biggest number it can hold I = 2147483647
!now add 1
I = i + 1 PRINT *, i END PROGRAM main SUBROUTINE trap_oflow(n) INTEGER :: n
! write error message to standard error
WRITE (7, *) 'integer overflow occurred, assigning 0 to result' n = 0
END SUBROUTINE trap_oflow
If you were to comment out the ON statement but keep the directive, the program would abort with a procedure traceback and a core dump. Compiling with the +check=alloption would have the same effect.
Trapping +Ctrl-C trap interrupts
A
•When the user enters the interrupt code from the terminal while the program is running or awaiting input
•During the execution of a PAUSEstatement
The trap procedure for a
You can use the
PROGRAM main COMMON i
ON CONTROLC CALL status DO i = 1, 100000
...! Long computation END DO END
SUBROUTINE status COMMON i
PRINT *, 'Currently on iteration ', i END SUBROUTINE status
When this program is run, a
Allowing core dumps
If a program includes the ONstatement and takes an exception other than the one specified by the exception keywords, the program will abort with a procedure traceback but without a core dump. If you want to allow a core dump for one or more signals for a program that includes the ONstatement, you must revise the program for each such signal.
For example, you may wish to handle
Trapping | 85 |