Compaq Fortran
User Manual for
OpenVMS Alpha Systems


Previous Contents Index


Chapter 7
Run-Time Errors

During execution, your program may encounter errors or exception conditions. These conditions can result from errors that occur during I/O operations, from invalid input data, from argument errors in calls to the mathematical library, from arithmetic errors, or from system-detected errors.

The Compaq Fortran Run-Time Library (RTL) provides default processing for error conditions, generates appropriate messages, and takes action to recover from errors whenever possible. However, you can explicitly supplement or override default actions by using the following methods:

This chapter describes how the Compaq Fortran RTL processes errors. It also provides information about using I/O specifiers for explicit error processing and control, and shows how these methods affect the default error processing of the Compaq Fortran RTL.

7.1 Compaq Fortran RTL Default Error Processing

The Compaq Fortran RTL contains condition handlers that process a number of errors that may occur during Compaq Fortran program execution. A default action is defined for each Fortran-specific error recognized by the Compaq Fortran RTL. The default actions described throughout this chapter occur unless overridden by explicit error-processing methods.

Unless you specify the /SYNCHRONOUS_EXCEPTIONS qualifier when you compile the program, error reporting of exceptions may be inexact; the exception may not be reported until a few instructions after the one that caused the exception. This makes continuation from an exception trap not feasible.

The way in which the Compaq Fortran RTL actually processes errors depends upon several factors:

The following FORTRAN command qualifiers are related to handling errors and exceptions:

For More Information:

7.1.1 Run-Time Message Format

The general form of Compaq Fortran run-time messages follows:


%FOR-severity-mnemonic, message-text

The contents of the fields in run-time messages follow:
% The percent sign identifies the line as a message.
FOR The facility code for Compaq Fortran 77 and Compaq Fortran.
severity A single character that determines message severity. The types of run-time messages are: Fatal (F), Error (E), and Informational (I).
mnemonic A 6- to 9-character name that uniquely identifies that message.
message_text Explains the event or reason why the message appears.

For example, the following message has a severity of Fatal, a mnemonic of ADJARRDIM, and message text of "adjustable array dimension error":


%FOR-F-ADJARRDIM, adjustable array dimension error

7.1.2 Run-Time Message Severity Levels

In order of greatest to least severity, the classes of run-time diagnostic messages are as follows:
Severity Code Description
F Fatal (severe)

This must be corrected. The program cannot complete execution and is terminated when the error is encountered, unless for I/O statements the program uses the END, EOR, or ERR branch specifiers to transfer control, perhaps to a routine that uses the IOSTAT specifier (see Section 7.2.1 and Section 7.2.2). You can also continue from certain fatal-level messages by using a condition handler.

E Error

This should be corrected. The program may continue execution, but the output from this execution may be incorrect.

I Informational

This should be investigated. The program continues executing, but output from this execution may be incorrect.

The severity depends on the source of the message. In some cases, certain FORTRAN command qualifiers can change the severity level or control whether messages are displayed (such as the /CHECK and /IEEE_MODE keywords).

7.2 Handling Errors

Whenever possible, the Compaq Fortran RTL does certain error handling, such as generating appropriate messages and taking necessary action to recover from errors.

When no recovery method is specified for a statement and a fatal-level error occurs, a message appears and the program terminates. To prevent program termination, you must include either an appropriate I/O error-handling specifier (see Section 7.2) or a condition handler that performs an unwind (see Chapter 14). The I/O error-handling specifier or condition handler might also handle error-level messages.

You can explicitly supplement or override default actions by using the following Compaq Fortran methods:

When a fatal error occurs during program execution, the Compaq Fortran RTL default action is to print an error message and terminate the program. You can establish an OpenVMS condition handler that performs an unwind for certain fatal errors.

These error-processing methods are complementary; you can use all of them within the same program. However, before attempting to write a condition handler, you should be familiar with the OpenVMS condition-handling facility (CHF) and with the condition-handling description in Chapter 14.

Using the END, EOR, or ERR branch specifiers in I/O statements prevent signaling (display) of errors, including secondary return values for file system errors, such as RMS errors. Using these specifiers prevent the transfer of control to a condition handler.

There are certain file system errors where no handler (condition handler or vector exception handler) exists. To obtain the secondary file system errors in these cases, remove the END, EOR, and ERR specifiers, recompile, relink, and rerun the program.

You do not need to remove the ERR or IOSTAT specifiers if you use a vectored exception handler (established using SYS$SETEXV), which will receive control instead of the ERR and IOSTAT specifiers. The ERRSNS subroutine allows you to obtain secondary return values for file system errors (see the Compaq Fortran Language Reference Manual).

7.2.1 Using the ERR, EOR, and END Branch Specifiers

When an error, end-of-record, or end-of-file condition occurs during program execution, the Compaq Fortran RTL default action is to display a message and terminate execution of the program.

You can use the ERR, EOR, and END specifiers in I/O statements to override this default by transferring control to a specified point in the program. To override this default action, there are three branch specifiers you can use in I/O statements to transfer control to a specified point in the program:

If an END, EOR, or ERR branch specifier is present, and the corresponding condition occurs, no message is displayed and execution continues at the statement designated in the appropriate specifier.

For example, consider the following READ statement:


READ (8, 50, END=400) X,Y,Z 

If an end-of-file condition occurs during execution of this statement, the contents of variables X, Y, and Z become undefined, and control is transferred to the statement at label 400. You can also add an ERR specifier to transfer control if an error condition occurs. Note that an end-of-file or end-of-record condition does not cause an ERR specifier branch to be taken.

When using nonadvancing I/O, use the EOR specifier to handle the end-of-record condition. For example:


150 FORMAT (F10.2, F10.2, I6) 
    READ (UNIT=20, FMT=150, SIZE=X, ADVANCE='NO', EOR=700) A, F, I 

You can also specify ERR as a keyword to such I/O statements as OPEN, CLOSE, or INQUIRE statement. For example:


  OPEN (UNIT=10, FILE='FILNAM', STATUS='OLD', ERR=999) 

If an error is detected during execution of this OPEN statement, control transfers to statement 999.

For More Information:

7.2.2 Using the IOSTAT Specifier

You can use the IOSTAT specifier to continue program execution after an I/O error and to return information about I/O operations. It can supplement or replace the END, EOR, and ERR transfers. Execution of an I/O statement containing the IOSTAT specifier suppresses printing of an error message and causes the specified integer variable, array element, or scalar field reference to be defined as one of the following:

Following execution of the I/O statement and assignment of an IOSTAT value, control transfers to the END, EOR, or ERR statement label, if any. If there is no control transfer, normal execution continues.

Your program can include the $FORIOSDEF library module from the FORSYSDEF library (automatically searched during compilation) to obtain symbolic definitions for the values of IOSTAT.

The values of the IOSTAT symbols from the $FORIOSDEF library module are not the same as the values of the Fortran condition symbols from the $FORDEF library module.

The symbolic names in the $FORIOSDEF library module have a form similar to the Fortran condition symbols:
Fortran Condition Symbol ($FORDEF) IOSTAT Symbolic Name ($FORIOSDEF)
FOR$_mnemonic FOR$IOS_mnemonic

Example 7-1 uses the ERR and IOSTAT specifiers to handle an OPEN statement error (in the FILE specifier). Condition symbols are included from the $FORIOSDEF library module (in FORSYSDEF).

Example 7-1 Handling OPEN Statement File Name Errors

     CHARACTER(LEN=40) :: FILNM      ! Typed file specification 
     INCLUDE '($FORIOSDEF)'          ! Include condition symbol definitions 
 
     DO I=1,4                        ! Allow four tries 
       FILNM = '' 
       WRITE (6,*)  'Type file name ' 
       READ (5,*) FILNM 
       OPEN (UNIT=1, FILE=FILNM, STATUS='OLD', IOSTAT=IERR, ERR=100) 
       WRITE (6,*) 'Opening file: ', FILNM 
        . 
        .   ! Process records 
        . 
 
       CLOSE (UNIT=1) 
       STOP 
 
 100   IF (IERR .EQ. FOR$IOS_FILNOTFOU) THEN 
         WRITE (6,*) 'File: ', FILNM, ' does not exist ' 
       ELSE IF (IERR .EQ. FOR$IOS_FILNAMSPE) THEN 
          WRITE (6,*) 'File: ', FILNM, ' was bad, enter new file name' 
       ELSE 
         PRINT *, 'Unrecoverable error, code =', IERR 
         STOP 
       END IF 
     END DO 
 
! After four attempts or a Ctrl/Z on the READ statement, allow program restart 
 
     WRITE (6,*) 'File not found. Type DIRECTORY to find file and run again' 
   END PROGRAM 

For More Information:

7.3 List of Run-Time Messages

Table 7-1 lists the Fortran-specific errors processed by the Compaq Fortran RTL. For each error, the table shows the Fortran-specific message mnemonic (follows either FOR$_ or FOR$IOS_ for condition symbols), the Fortran-specific message number, the severity (fatal, error, or informational), the message text. For more detailed descriptions of errors processed by the Compaq Fortran RTL, see Table B-1.

Table 7-1 Summary of Run-Time Errors
Mnemonic Number1 Severity Message Text
NOTFORSPE 2 1 F not a Fortran-specific error
BUG_CHECK 8 F internal consistency check failure
SYNERRNAM 17 F syntax error in NAMELIST input
TOOMANVAL 18 F too many values for NAMELIST variable
INVREFVAR 19 F invalid reference to variable in NAMELIST input
REWERR 20 F REWIND error
DUPFILSPE 21 F duplicate file specifications
INPRECTOO 22 F input record too long
BACERR 23 F BACKSPACE error
ENDDURREA 24 F end-of-file during read
RECNUMOUT 25 F record number outside range
OPEDEFREQ 26 F OPEN or DEFINE FILE required
TOOMANREC 27 F too many records in I/O statement
CLOERR 28 F CLOSE error
FILNOTFOU 29 F file not found
OPEFAI 30 F open failure
MIXFILACC 31 F mixed file access modes
INVLOGUNI 32 F invalid logical unit number
ENDFILERR 33 F ENDFILE error
UNIALROPE 34 F unit already open
SEGRECFOR 35 F segmented record format error
ATTACCNON 36 F attempt to access non-existent record
INCRECLEN 37 F inconsistent record length
ERRDURWRI 38 F error during write
ERRDURREA 39 F error during read
RECIO_OPE 40 F recursive I/O operation
INSVIRMEM 41 F insufficient virtual memory
NO_SUCDEV 42 F no such device
FILNAMSPE 43 F file name specification error
INCRECTYP 44 F inconsistent record type
KEYVALERR 45 F keyword value error in OPEN statement
INCOPECLO 46 F inconsistent OPEN/CLOSE parameters
WRIREAFIL 47 F write to READONLY file
INVARGFOR 48 F invalid argument to Fortran Run-Time Library
INVKEYSPE 49 F invalid key specification
INCKEYCHG 50 F inconsistent key change or duplicate key
INCFILORG 51 F inconsistent file organization
SPERECLOC 52 F specified record locked
NO_CURREC 53 F no current record
REWRITERR 54 F REWRITE error
DELERR 55 F DELETE error
UNLERR 56 F UNLOCK error
FINERR 57 F FIND error
FMYSYN 58 I format syntax error at or near xxx
LISIO_SYN 3 59 F list-directed I/O syntax error
INFFORLOO 60 F infinite format loop
FORVARMIS 3 61 F or I 4 format/variable-type mismatch
SYNERRFOR 62 F syntax error in format
OUTCONERR 3,4 63 E or I 4 output conversion error
INPCONERR 3 64 F input conversion error
FLTINV 65 E floating invalid
OUTSTAOVE 66 F output statement overflows record
INPSTAREQ 67 F input statement requires too much data
VFEVALERR 3 68 F variable format expression value error
INTOVF 70 F integer overflow
INTDIV 71 F integer divide by zero
FLTOVF 72 E floating overflow
FLTDIV 73 E floating divide by zero
FLTUND 74 E floating underflow
SUBRNG 77 F subscript out of range
WRONUMARG 80 F wrong number of arguments
INVARGMAT 81 F invalid argument to math library
UNDEXP 5 82 F undefined exponentiation
LOGZERNEG 5 83 F logarithm of zero or negative value
SQUROONEG 5 84 F square root of negative value
SIGLOSMAT 5 87 F significance lost in math library
FLOOVEMAT 5 88 F floating overflow in math library
FLOUNDMAT 89 E floating underflow in math library
ADJARRDIM 6 93 F adjustable array dimension error
INVMATKEY 94 F invalid key match specifier for key direction
FLOCONFAI 95 E floating point conversion failed
FLTINE 140 E floating inexact
ROPRAND 144 F reserved operand
ASSERTERR 145 F assertion error
NULPTRERR 146 F null pointer error
STKOVF 147 F stack overflow
STRLENERR 148 F string length error
SUBSTRERR 149 F substring error
RANGEERR 150 F range error
INVREALLOC 151 F allocatable array is already allocated
RESACQFAI 152 F unresolved contention for Compaq Fortran RTL global resource
INVDEALLOC 153 F allocatable array is not allocated
INVDEALLOC2 173 F A pointer passed to DEALLOCATE points to an array that cannot be deallocated
SHORTDATEARG 175 F DATE argument to DATE_AND_TIME is too short (LEN=n), required LEN=8
SHORTTIMEARG 176 F TIME argument to DATE_AND_TIME is too short (LEN=n), required LEN=10
SHORTZONEARG 177 F ZONE argument to DATE_AND_TIME is too short (LEN=n), required LEN=5
DIV 178 F divide by zero
ARRSIZEOVF 179 F cannot allocate array --- overflow on array size calculation
UNFIO_FMT 256 F unformatted I/O to unit open for formatted transfers
FMTIO_UNF 257 F formatted I/O to unit open for unformatted transfers
DIRIO_KEY 258 F direct-access I/O to unit open for keyed access
SEQIO_DIR 259 F sequential-access I/O to unit open for direct access
KEYIO_DIR 260 F keyed-access I/O to unit open for direct access
OPERREQDIS 264 F operation requires file to be on disk or tape
OPEREQSEQ 265 F operation requires sequential file organization and access
ENDRECDUR 268 F end of record during read
FLOINEEXC 296 I nn floating inexact traps
FLOINCEXC 297 I nn floating invalid traps
FLOOVREXC 298 I nn floating overflow traps
FLODIV0EXC 299 I nn divide-by-zero traps
FLOUNDEXC 300 I nn floating underflow traps


1Although most error numbers are returned as IOSTAT values, the following are not: 1, 24 (END specifier), 41, 58, 70--75, 77, 80-89, 95, 140--150, 151, 153, 173, 175--177, 179, 266, 268 (EOR specifier), 297, 298, 299, 300. You can use condition symbols (FOR$_mnemonic or FOR$IOS_mnemonic) to obtain the number (see Section 7.2.2). Some of these error numbers are returned as STAT= values in either the ALLOCATE (41, 151, 179) or DEALLOCATE (41, 153, 173) Fortran statement.
2The FOR$_NOTFORSPE error (number 1) indicates an error not reportable through any other message. If you call ERRSNS, an error of this kind returns a value of 1. Use the fifth argument of the call to ERRSNS (condval) to obtain the unique system condition value that identifies the error.
3For error numbers 59, 61, 63, 64, and 68, the ERR transfer is taken after completion of the I/O statement. The resulting file status and record position are the same as if no error had occurred. Other I/O errors take the ERR transfer as soon as the error is detected, and file status and record position are undefined.
4For errors 61 and 63, the severity depends on the /CHECK keywords in effect during compilation (see Section 2.3.11). If no ERR address is defined for error number 63, the program continues and the entire overflowed field is filled with asterisks to indicate the error in the output record.
5Function return values for error numbers 82, 83, 84, 87, 88, and 89 can be modified by means of user-written condition handlers. (See Chapter 14 for information about user-written condition handlers.)
6If error number 93 (FOR$_ADJARRDIM) occurs and a user-written condition handler causes execution to continue, any reference to the array in question may cause an access violation.

The message mnemonic shown in the first column is part of the condition status code symbols signaled by the Compaq Fortran RTL I/O support routines. You can define these symbolic values in your program by including the library module $FORDEF or $FORIOSDEF from the system-supplied default library FORSYSDEF.TLB:

If you will be using the IOSTAT specifier for error handling, you should include the $FORIOSDEF library module (instead of $FORDEF) from the FORSYSDEF.TLB library (see Section 7.2.2).

The standard Compaq Fortran error numbers that are generally compatible with other versions of Compaq Fortran are shown in the second column. Most of these error values are returned to IOSTAT variables when an I/O error is detected.

The codes in the third column indicate the severity of the error conditions (see Section 7.1.2).

For more detailed descriptions of errors processed by the Compaq Fortran RTL, see Table B-1 or type the following DCL command to obtain a list of mnemonics (such as ADJARRDIM):


$ HELP FORTRAN ERROR RUN_TIME

For More Information:


Previous Next Contents Index