Previous Application Programming: Debugging and Error-Handling Next

Controlling and Recovering from Errors

IDL divides possible execution errors into three categories: input/output, math, and all others. There are three main error-handling routines: CATCH, ON_ERROR, and ON_IOERROR. CATCH is a generalized mechanism for handling exceptions and errors. The ON_ERROR routine handles regular errors when an error handler established by the CATCH procedure is not present. The ON_IOERROR routine allows you to change the default way in which input/output errors are handled. The FINITE and CHECK_MATH routines provide control over math errors.

You can also write code in such a manner as to anticipate and handle potential errors, especially when you are writing your own routines. See the following topics in Creating Procedures and Functions for details:

Interaction of CATCH, ON_ERROR, and ON_IOERROR

Error handlers established by calls to CATCH supersede calls to ON_ERROR. However, calls to ON_IOERROR made in the procedure that causes an I/O error supersede any error handling mechanisms created with CATCH and the program branches to the label specified by ON_IOERROR.

The following figure is a flow chart of how errors are handled in IDL.

Figure 8-4: Error Handling in IDL

Figure 8-4: Error Handling in IDL

  IDL Online Help (March 06, 2007)