Performs a specified action when a command or program executed within a command procedure encounters an error condition or is interrupted by Ctrl/Y. The specified actions are performed only if the command interpreter is enabled for error checking or Ctrl/Y interrupts (the default conditions). Use the ON command only in a command procedure. Format ON condition THEN [$] command
1 – Parameters
condition Specifies either the severity level of an error or a Ctrl/Y interrupt. Specify one of the following keywords, which may be abbreviated to one or more characters: WARNING Return status of warning occurs ($SEVERITY equals 0). ERROR Return status of error occurs ($SEVERITY equals 2). SEVERE_ERROR Return status of error occurs ($SEVERITY equals 4). CONTROL_Y Ctrl/Y character occurs on SYS$INPUT. The default error condition is ON ERROR THEN EXIT. command Specifies the DCL command line to be executed. Optionally, you can precede the command line with a dollar sign ($). If you specified an error condition as the condition parameter, the action is taken when errors equal to or greater than the specified level of error occur.
2 – Examples
1. $ ON SEVERE_ERROR THEN CONTINUE A command procedure that contains this statement continues to execute normally when a warning or error occurs during execution. When a severe error occurs, the ON statement signals the procedure to execute the next statement anyway. Once the statement has been executed as a result of the severe error condition, the default action (ON ERROR THEN EXIT) is reinstated. 2.$ ON ERROR THEN GOTO BYPASS $ RUN A $ RUN B . . . $ EXIT $ BYPASS: $ RUN C If either program A or program B returns a status code with a severity level of error or severe error, control is transferred to the statement labeled BYPASS and program C is run. 3.$ ON WARNING THEN EXIT . . . $ SET NOON $ RUN [SSTEST]LIBRA $ SET ON . . . The ON command requests that the procedure exit when any warning, error, or severe error occurs. Later, the SET NOON command disables error checking before executing the RUN command. Regardless of any status code returned by the program LIBRA.EXE, the procedure continues. The next command, SET ON, reenables error checking and reestablishes the most recent ON condition. 4.$ ON CONTROL_Y THEN GOTO CTRL_EXIT . . . $ CTRL_EXIT: $ CLOSE INFILE $ CLOSE OUTFILE $ EXIT The ON command specifies action to be taken when Ctrl/Y is pressed during the execution of this procedure: the GOTO command transfers control to the line labeled CTRL_EXIT. At CTRL_EXIT, the procedure performs cleanup operations (in this example, closing files and exiting).