|
Application Programming: Debugging and Error-Handling |
|
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. When execution is interrupted, a current-line 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, IDLDE will display the file automatically.
When execution stops, you can take the following steps:
To understand what is happening during program execution, consider setting breakpoint and stepping through the code. See Working with Breakpoints.
A simple procedure, called BROKEN, has been included in the IDL distribution. An error occurs when BROKEN is executed. Start the IDLDE. Call the BROKEN procedure by entering:
BROKEN
at the IDL command line. An error is reported in the Output Log window and an editor window containing the file BROKEN.PRO appears and contains the following code:
; $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. Since execution stopped at line 4, that line is highlighted with an arrow.
There are several ways of fixing 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. We can also define the variable i on the fly and continue execution of the program without making any changes to the program file. We'll do this first, then go back and edit the program to accept a command-line parameter. To define the variable i and assign it the value 10, enter at the command line:
i = 10
And select run to continue execution.
IDL Online Help (March 06, 2007)