Routines (alphabetical) > Routines: O > ON_ERROR

# ON_ERROR

The ON_ERROR procedure determines the action taken when an error is detected inside an IDL user procedure or function by setting state information applying to the current routine and all nested routines. If an override exists within the nested routine, it takes precedence over the ON_ERROR call. ON_ERROR determines the action when no error handlers established with the CATCH procedure are found.

## Example

One useful option is to use ON_ERROR to cause control to be returned to the caller of a procedure in the event of an error. The statement:

ON_ERROR, 2

placed at the beginning of a procedure will have this effect. Include this statement in library procedures and other routines that will be used by others once the routines have been debugged. This form of error recovery makes debugging a routine difficult because the routine is exited as soon as an error occurs; therefore, it should be added once the code is completely tested.

Note: Error handlers established by CATCH supersede calls to ON_ERROR made in the same procedure.

## Syntax

ON_ERROR, N

## Arguments

### N

An integer that specifies the action to take. Valid values for N are:

0 | Stop immediately at the statement that caused the error and print the current program stack. This is the default action.
1 | Print the current program stack, return to the main program level and stop.
2 | Return to the caller of the program unit that called ON_ERROR, then stop and print the program stack from the caller up to the main program level.
3 | Return to the program unit that called ON_ERROR, then stop and print the program stack from this program unit up to the main program level.

## Keywords

None.

## Version History

Original | Introduced

## See Also

CATCH, MESSAGE