COBOL condition handling semantics

COBOL native condition handling is very different from C, PL/I, or Fortran native condition handling.

COBOL provides some condition handling on a statement-by-statement basis; for example, the ON EXCEPTION phrase of the CALL statement, the ON EXCEPTION phrase of the INVOKE statement, and the ON SIZE ERROR phrase of the COMPUTE statement. For other conditions, COBOL generally reports the error. An assembler user exit is available for COBOL to specify events that should cause an abend.

For more information about user exits, see Using runtime user exits. For a discussion of COBOL condition handling in an ILC application, see z/OS V2R1.0 Language Environment Writing Interlanguage Communication Applications. The following discussion applies to stacks comprised solely of COBOL programs.

If an exception occurs in a COBOL program, COBOL does nothing until every condition handler at every stack frame has been interrogated.

After all stack frames have been visited, COBOL does the following:

  1. Checks to see if the condition has a facility ID of IGZ (is a COBOL-specific condition). If not, COBOL percolates the condition to the Language Environment condition manager.
  2. Handles the condition based on its severity (see Table 1 for an explanation of severity codes and their meaning under Language Environment).

    If the condition severity is 1, a message describing the condition is issued to the destination specified in the MSGFILE runtime option, and processing resumes in the program in which the error occurred.

    If the severity is 2 or above, COBOL percolates the condition to the Language Environment condition manager. The Language Environment default action then takes place.