C, COBOL, and PL/I scenario: exception occurs in C

This scenario describes the behavior of an application that contains C, COBOL, and PL/I. Refer to Figure 1 throughout the following discussion.

Figure 1. Stack contents when the exception occurs in C
Stack contents when the exception occurs in C.

In this example, X.COBOL invokes Y.PLI, which invokes Z.C. A condition is raised in Z.C. The stack contains what is shown in Figure 1. No user-written condition handlers have been registered using CEEHDLR for any stack frame, and no PL/I ON-units have been established.

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

  1. In the enablement step, it is determined whether the exception in the C routine should be enabled and treated as a condition. If any of the following are true, the exception is ignored, and processing continues at the next sequential instruction after where the exception occurred:
    • You specified SIG_IGN for the exception in a call to signal().

      However, the system or user abend represented by the Language Environment message 3250 and the signal(SIGABND) is not ignored. The enclave is terminated.

    • The exception is one of those listed as masked in Table 2.
    • You do not specify any action, but the default action for the condition is SIG_IGN (see Table 2).
    • You are running under CICS® and a CICS handler is pending.
    If you do none of these things, the condition is enabled and processed as a condition.
  2. If a user-written condition handler is registered using CEEHDLR on the Z.C stack frame, it receives control. If it issues a resume, the condition handling step ends. Processing continues in the routine to which the resume cursor points.

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

  3. If a C signal handler has been registered for the condition on the Z.C stack frame, it is given control. If it issues a resume or a call to longjmp(), the condition handling step ends. Processing resumes in the routine to which the resume cursor points.

    In this example, no signal handler is registered, so the condition is percolated.

  4. The condition is still unhandled. If C does not recognize the condition, or if the C default action (listed in Table 2) is to terminate, the condition is percolated.
  5. No user-written condition handlers can be registered using CEEHDLR on the Y.PLI stack frame, because they cannot be written in PL/I. If an ON-unit that corresponds to the condition being processed exists on the Y.PLI stack frame, however, 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 has been established for the condition on the Y.PLI stack frame, so the condition is percolated.

  6. If a user-written condition handler has been registered using CEEHDLR on the X.COBOL stack frame, it is given control. (User-written condition handlers written in COBOL must be compiled with COBOL/370, COBOL for MVS & VM, or COBOL for OS/390 & VM.) If it issues a resume, with or without moving the resume cursor, the condition handling step ends. Processing continues in the routine to which the resume cursor points.
  7. 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 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, a FINISH ON-unit or user-written condition handler is run if the stack frame in which it is established is reached.
    • If no condition handler moves the resume cursor and issues a resume, Language Environment terminates the thread.

User handlers that you register using CEEHDLR must be written in the same language you are using to do the registration.