ON

From VSI OpenVMS Wiki
Jump to: navigation, search

ON is a command that 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. ON is a command executed inside of DCL; no image is invoked.

The default is ON ERROR THEN EXIT.

Syntax

    ON  condition THEN [$] command

Conditions

The following are valid conditions for the ON command:

  • 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.

ON overrides the default error processing, which means that when error conditions milder than specified by the ON statement occur, the command procedure displays the message and continues.

Once the ON command has been executed, the default action (ON ERROR THEN EXIT) is reinstated.

Examples

 $ 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.