Exception occurs in COBOL

This scenario describes the behavior of an application that contains a COBOL and a PL/I routine. Refer to Figure 1 throughout the following discussion. In this scenario, a PL/I main routine invokes a COBOL subroutine. An exception occurs in the COBOL subroutine.

Figure 1. Stack contents when the exception occurs in COBOL
The stack contents when the exception occurs in COBOL

The actions taken follow the three Language Environment condition handling steps: enablement, condition, and termination imminent.

  1. In the enablement step, COBOL determines whether the exception that occurred should be handled as a condition.
    • If the exception is to be ignored, control is returned to the next sequential instruction after where the exception occurred.
    • If the exception is to be enabled and processed as a condition, the condition handling step takes place.
  2. If a user-written condition handler has been registered using CEEHDLR on the COBOL stack frame, it is given control.

    If it issues a resume, the condition handling step ends. Processing continues in the routine to which the resume cursor points.

    Two areas to watch out for here are resuming from an IBM® condition of severity 2 or greater (see the information about coding a user-written condition handler in z/OS Language Environment Programming Guide) and moving the resume cursor in an application that contains a COBOL program (see GOTO out-of-block and move resume cursor).

    In this example, no user-written condition handler is registered for the condition, so the condition is percolated.

  3. Is a user-written condition handler has been registered on the PL/I stack frame using CEEHDLR, it is given control. If it issues a resume, the condition handling step ends. Processing continues in the routine at the point where the resume cursor points. In this example, no user-written condition handler is registered for the condition, so the condition is percolated.
  4. If an ON-unit has been established for the condition being processed on the PL/I stack frame, it is given control. If it issues a GOTO out-of-block, the condition handling step ends. Execution resumes at the label of the GOTO. In this example, no ON-unit is established for the condition, so the condition is percolated.
  5. After all stack frames have been visited, and if the condition is COBOL-specific (with a facility ID of IGZ), the COBOL default action occurs. Otherwise, the Language Environment default actions take place.
  6. What happens next depends on whether the condition is promotable to the PL/I ERROR condition. The following can happen:
    • If the condition is not promotable to the PL/I ERROR condition, then the Language Environment default actions take place, as described in Table 1. Condition handling ends.
    • If the PL/I default action for the condition is to promote it to the PL/I ERROR condition, The condition is promoted, and another pass of the stack is made to look for ERROR ON-units or user-written condition handlers. If an ERROR ON-unit or user-written condition handler is found, it is invoked.
    • If either of the following occurs:
      • An ERROR ON-unit or user-written condition handler is found, but it does not issue a GOTO out of block or similar construct
      • No ERROR ON-unit or user-written condition handler is found
      then the ERROR condition is promoted to T_I_U (Termination Imminent due to an Unhandled condition). Condition handling now enters the termination imminent step. Because T_I_U maps to the PL/I FINISH condition, both FINISH ON-units and user-written condition handlers can be run if the stack frames in which they are established is reached.
    • If no condition handler moves the resume cursor and issues a resume, Language Environment terminates the thread.