EXCEPTION PROCEDURE Declaration

The EXCEPTION PROCEDURE declaration enables you to designate a procedure that must be executed automatically by the system whenever an abnormal exit occurs for the block in which the EXCEPTION PROCEDURE declaration is contained.

<exception procedure declaration>

── EXCEPTION PROCEDURE ──<exception procedure identifier>── ; ─────────►
►─<unlabeled statement>────────────────────────────────────────────────┤

<exception procedure identifier>

──<identifier>─────────────────────────────────────────────────────────┤

An exception procedure is invoked when a block containing it terminates in any way other than a normal exit. It is not automatically invoked on a normal exit of the block. Abnormal exits include the following:

  • A discontinue (DS) command

  • A bad branch (GO TO) leading out of the block

  • Any unhandled fault

An exception procedure can be invoked directly like any other procedure; it can be passed as a parameter (with limitations), and so on. The use of a procedure as an exception procedure is allowed only to the block that contains the procedure. A block or procedure cannot contain more than one EXCEPTION PROCEDURE declaration (or an EXCEPTION PROCEDURE declaration and an EPILOG PROCEDURE declaration).

If a fault occurs, and an ON declaration exists to handle the fault, the exception procedure is invoked only if an abnormal exit of the block occurs. Thus, the exception procedure is not invoked if the ON declaration includes a GO TO clause linked to a label inside the block in which the EXCEPTION PROCEDURE declaration occurs.