What Happens When Execution Stops
In the default case, whenever an error is detected by IDL during the execution of a program, program execution stops and an error message is printed. The execution context is that of the program unit (procedure, function, or main program) in which the error occurred. If you are using the IDL Workbench when execution is interrupted, the code in which the error occurred is displayed in an editor window and an indicator is placed next to the line that will be executed when processing resumes. The routine being compiled need not already be shown in an editor window. If a routine compiled with the .RUN, .RNEW, or .COMPILE executive commands contains an error, the IDL Workbench will display the file automatically.
When execution stops, you can take the following steps:
- Correct the problem and continuing program execution (see Correcting Errors During Execution)
- Anticipate and handle errors to avoid execution halt (Controlling and Recovering from Errors)
To understand what is happening during program execution, consider setting breakpoint and stepping through the code. See Working with Breakpoints.
Example: Correcting Undefined Variable
A simple procedure, called BROKEN, has been included in the IDL distribution. An error occurs when BROKEN is executed. Start the IDL Workbench. Call the BROKEN procedure by entering:
at the IDL command line. An error is reported in the console; if you are using the IDL Workbench, an editor window displays the file BROKEN.PRO :
; $Id: broken.pro,v 1.1 1996/10/01 22:01:54 doug Exp $ PRO BROKEN PRINT, i PRINT, i*2 PRINT, i*3 PRINT, i*4 END
A "Variable is undefined" error has occurred. The line of code that first references the undefined variable is noted in the error message and (if applicable) highlighted with an arrow in the editor.
There are several ways to fix this error. We could edit the program file to explicitly define the variable i, or we could change the program so that it accepts a parameter at the command line. Instead, we'll define the variable i on the fly and continue execution of the program without making any changes to the program file. To define the variable i and assign it the value 10, enter at the command line:
Next, enter
at the command line, or select Run → Resume in the IDL Workbench.