Locating Run-Time Errors in the Debugger

For many types of errors, using the Debugger can help you isolate the cause of errors. This section discusses the following topics:

Effect of Certain Compiler Options

Be aware that your program must use compiler options that allow the debugger to catch the appropriate error conditions:

In most cases, your program will automatically stop at the point where the exception occurs, allowing you to view the source code and values of variables. If the error is related to an I/O statement, see Viewing the Call Stack and Using the Context Menu.

Debugging an Exception

You can request that the program always stop when a certain type of exception occurs. Certain exceptions are caught by default by the Visual Fortran run-time library, so your program stops in the run-time library code. In most cases, you want the program to instead stop in your program's source code.

To change how an exception is handled in the debugger:

  1. Start the debugger and stop execution at the initial breakpoint.
  2. In the Debug menu, click Exceptions
  3. View the displayed exceptions.
  4. Select each type of exception to be changed and change it from "Stop if not handled" to "Stop Always"
  5. Continue program execution by clicking Go in the Debug menu.
  6. When the exception occurs, you can now view the source line being executed, examine current variable values, execute the next instruction, and so on to help you better understand that part of your program. If the error is related to an I/O statement, also see Viewing the Call Stack and Using the Context Menu.
  7. After you locate the error and correct the program, consider whether you want to reset the appropriate type of exception to "Stop if not handled" before you debug the program again.

For machine exceptions, you can use the just-in-time debugging feature to debug your programs as they run outside of the visual development environment, if both of the following items have been set:

Viewing the Call Stack and Using the Context Menu

If you want to view where in the hierarchy of routines your program in currently executing, such as after your program stops at the point where an exception occurs, you can view the Call Stack window and Context menu in the debugger:

  1. Start the debugger and stop at a breakpoint
  2. In the View menu, click Debug Windows
  3. In the submenu, click Call Stack

A severe unhandled I/O programming error (such as an End-of-File condition) can occur while the program is executing in the debugger. When this occurs, the Fortran run-time system will raise a debug event automatically to stop program execution, allowing display of the Call Stack Display.

When the severe unhandled I/O error occurs in the debugger:

Click OK to dismiss the information box.

Scanning down the Call Stack display, there will be a few frames from NTDLL and the Fortran run-time system displayed, and then the actual Fortran routine with the I/O statement that caused the error. In the Context menu, select the Fortran routine to display the Fortran code. The green arrow points to the I/O statement that caused the error.

You can view the Context menu (after Context:) to help locate the source code line that executed the I/O statement. The Context menu appears in the top of the Variables window (see Debugging the Squares Example Program). Use the Context menu to select the viewing context for the routine (use the arrow at the right to display selections).

This action all occurs after the error message and traceback information has been displayed. The error message and traceback information is available in the program output window. To view the program output window, either iconize (minimize) the visual development environment or click the icon for the output window in the task bar. You should not need the stack dump because you have the Call Stack window in the visual development environment, but the error message with the file name might be useful to see.

For more information: