The ON_IOERROR procedure specifies a statement to be jumped to if an I/O error occurs in the current procedure. Normally, when an I/O error occurs, an error message is printed and program execution is stopped. If ON_IOERROR is called and an I/O related error later occurs in the same procedure activation, control is transferred to the designated statement with the error code stored in the system variable
The effect of ON_IOERROR can be canceled by using the label "NULL" in the call.
Statement to jump to when I/O error is encountered.
The following code segment reads an integer from the keyboard. If an invalid number is entered, the program re-prompts.
i = 0 ; Number to read: valid = 0 ; Valid flag WHILE valid EQ 0 DO BEGIN ON_IOERROR, bad_num READ, 'Enter Number: ', i ;If we get here, i is good. VALID = 1 bad_num: IF ~ valid THEN $ PRINT, 'You entered an invalid number.' ENDWHILE END
CATCH, MESSAGE, ON_ERROR, and Controlling Errors.