Addressing Runtime Errors

When IDL encounters a runtime error — any problem that causes execution to halt in a running program — it displays a message in the Console view indicating the file and line on which the error occurred. The file containing the code that generated the error is displayed in an editor window, and the line containing the error is marked with an arrow.

To see this feature in action, run the BROKEN routine. The BROKEN routine is included in the file broken.pro, found in the examples/doc/language subdirectory of the IDL distribution; it contains a reference to an undefined IDL variable, which causes a runtime error.

Note that the error is reported in the Console view:

debug_runtime_error_console.gif

and indicated in the editor:

debug_runtime_error_editor.gif

Many runtime errors can be corrected in place, and execution can resume. In the above example, execution halted because the variable i is not defined. If we assign a value to the variable at the command line:

i = 10

and then select Resume from the Run menu (or press F8), IDL uses the specified value for the variable and the BROKEN routine can run to completion. Alternately, you can change the value of the variable using the Variables view, as described in Profiling Your Code.

Note that if define a variable's value as shown above, the variable is only defined in the context of the running routine. The assignment is lost when the routine finishes. This means that the next time you run the routine, the same undefined variable error will occur. To fix the problem permanently, add a line like

i = 10 

above the first PRINT statement in the broken.pro file.