This topic provides some guidelines for locating the cause of exceptions and run-time errors. Intel Fortran run-time error messages do not usually indicate the exact source location causing the error. The following compiler options are related to handling errors and exceptions:
The -check [keyword] (Linux
and Mac OS) or /check[:keyword] (Windows) option
generates extra code to catch certain conditions at run time. For example,
if you specify the keyword of bounds, the debugger
will catch
and stop at array or character string bounds errors. You can specify the
keyword of bounds to generate code to perform
compile-time and run-time checks
on array subscript and character substring expressions. An error is reported
if the expression is outside the dimension of the array or the length
of the string. The keyword of uninit generates
code for dynamic checks of uninitialized variables. If a variable is read
before written, a run-time error routine will be called.
The noformat and nooutput_conversion
keywords reduce the severity level of the associated run-time error to
allow program continuation.
The pointers keyword generates code to test for disassociated pointers
and unallocatable arrays.
The following - check pointers (Linux and Mac OS) or /check:pointers
(Windows) examples result in various output messages.
Example 1: Allocatable variable not allocated
real, allocatable:: a(:)
! allocate(a(4)) ! if a is unallocated, the next statement gets an error with "check pointers"
a=17
print *,a
end
Output 1:
forrtl: severe (408): fort: (8): Attempt to fetch from allocatable variable A when it is not allocated
Example 2: Pointer not associated
real, pointer:: a(:)
allocate(a(5))
a=17
print *,a
deallocate(a) ! once a is deallocated, the next statement gets an error with "check pointers"
a=20
print *,a
end
Output 2:
17.00000 17.00000 17.00000 17.00000 17.00000
forrtl: severe (408): fort: (7): Attempt to use pointer A when it is not associated with a target
Example 3: Cray pointer with zero value
pointer(p,a)
real, target:: b
! p=loc(b) ! if integer pointer p has no address assigned to it,
! ! the next statement gets an error with "check pointers"
b=17.
print *,a
end
Output 3:
forrtl: severe (408): fort: (9): Attempt to use pointee A when its corresponding integer pointer P has the value zero
The -ftrapuv (Linux and Mac OS) or /Qtrapuv (Windows) option is useful in detecting uninitialized variables. It sets uninitialized local variables that are allocated on the stack to a value that is typically interpreted as a very large integer or an invalid address. References to these variables, which are not properly initialized by the application, are likely to cause run-time errors that can help you detect coding errors.
The -traceback (Linux and Mac OS) or /traceback (Windows) option generates extra information in the object file to provide source file traceback information when a severe error occurs at run time. This simplifies the task of locating the cause of severe run-time errors. Without traceback, you could try to locate the cause of the error using a map file and the hexadecimal addresses of the stack displayed when a severe error occurs. Certain traceback-related information accompanies severe run-time errors, as described in Using Traceback Information.
The -fpe (Linux and Mac OS) or /fpe (Windows) option controls the handling of floating-point arithmetic exceptions (IEEE arithmetic) at run time. If you specify the -fpe3 (Linux and Mac OS) or /fpe:3 (Windows) compiler option, all floating-point exceptions are disabled, allowing IEEE exceptional values and program continuation. In contrast, specifying -fpe0 or /fpe:0 stops execution when an exceptional value (such as a NaN) is generated or when attempting to use a denormalized number, which usually allows you to localize the cause of the error.
The -warn and -nowarn (Linux and Mac OS) or /warn and /nowarn (Windows) options control compile-time warning messages, which, in some circumstances, can help determine the cause of a run-time error.
On Linux and Mac OS systems, the -fexceptions option enables C++ exception handling table generation, preventing Fortran routines in mixed-language applications from interfering with exception handling between C++ routines.
On Windows systems, the Compilation Diagnostics Options in the IDE control compile-time diagnostic messages, which, in some circumstances can help determine the cause of a run-time error.
See also Understanding Run-Time Errors.