Condition-handling model description

The Language Environment® condition handler is based on a stack frame model. A stack frame is an area of storage that can contain automatic variables, information on program linkage and condition handling, and other information. The stack frame is allocated using Language Environment-managed storage, either HEAP or STACK, depending on the language being used. It is created through any of the following,
  • A function call in C or C++
  • Entry into a compile unit in COBOL
  • Entry into a procedure or begin block in PL/I
  • Entry into an ON-unit in PL/I
Each routine adds a unique stack frame, in a LIFO manner, to the Language Environment storage, either HEAP or STACK. User-written condition handlers (registered through CEEHDLR) are associated with each stack frame. In addition, HLL handling semantics can affect the processing conditions at each stack frame. For an illustration of the Language Environment runtime stack and its divisions into stack frames, see Figure 1.
Figure 1. Condition-handling stack configuration
Runtime stacks are divided into stack frames such as the initial stack and COBOL handler.

Each Language Environment user condition handler is explicitly registered through the callable service CEEHDLR or through the USRHDLR runtime option. Language-defined handling mechanisms are registered through language-provided constructs, such as the PL/I ON statement or the C signal() function. When a routine returns to its caller, its stack frame is removed from the stack and the associated handlers are automatically unregistered. Semantics associated with a routine are honored; for example, PL/I semantics on a return specify that any ON-units within a routine will be unregistered. If the USRHDLR runtime option is used, the user-written condition handler is registered at stack frame 0.

A condition is signaled within Language Environment as a result of one of the following occurrences:
  • A hardware-detected interrupt
  • An operating system-detected exception
  • A condition generated by Language Environment callable services
  • A condition explicitly signaled within a routine

The first three types of conditions are managed by Language Environment and signaled if appropriate. The last may be signaled by user-written code through a call to the service CEESGL or signaled by HLL semantics such as SIGNAL in PL/I or raise in C.

When a condition is signaled, whether by a user routine, by Language Environment in response to an operating system or hardware detected condition, or by a callable service, Language Environment directs the appropriate condition handlers in the stack frame to handle the condition. Condition handling proceeds first with user-written condition handlers in the queue, if present, then with any HLL-specific condition handlers, such as a PL/I ON-unit or a C signal handler, that may be established. The process continues for each frame in the stack, from the most recently allocated to the least recently allocated.

If a condition remains unhandled after the stack is traversed, the condition is handled by either Language Environment or by the default semantics of the language where the condition occurred.