Invoking condition handlers

After a condition has been enabled, Language Environment steps through the stack and passes control to the most recently established condition handling routines in the stack. Condition handling routines can be in the form of the Debug Tool, a user-written condition handler, or a language-specific condition handling mechanism:
Debug tool
If you have invoked a debug tool using the TEST runtime option or the CEETEST callable service (see z/OS Language Environment Programming Reference), the debug tool gains control when a condition occurs. Unless a condition is promoted and is passed through the stack again for additional condition handling, a debug tool is invoked only once per stack.
User-written condition handler
User-written condition handlers are routines that you supply to handle specific conditions that might arise in the runtime environment. As shown in Figure 1, a LIFO queue containing zero or more user-written condition handlers is associated with each stack frame. A different queue exists for each stack frame. For example, if routine A calls routine B, there is a new queue associated with the stack frame for routine B.
Figure 1. Queues of user-written condition handlers
Control is passed to the most recently established condition handling routines in the stack.

User-written condition handlers are registered on a stack frame-by-stack frame basis using the CEEHDLR callable service. A call to CEEHDLR from a given routine adds a user-written condition handler onto the queue for the stack frame associated with that routine. Registering a condition handling routine using CEEHDLR implicitly requests Language Environment to pass control to this routine when a condition occurs. For example, you could call CEEHDLR to register two user-written condition handlers for the same stack frame, one that handles floating-point underflow conditions and another that handles floating-point divide conditions.

The most recent user condition handler registered using CEEHDLR is the first to be invoked by Language Environment. Note that you could also register a single user condition handler to handle both of these conditions.

The user-written condition handlers can respond to a condition in any of the ways described in Responses to conditions.

User-written condition handlers are given a chance to handle a given condition before the language-specific condition handling semantics described in "Language-specific condition handling semantics" take effect.

Language-specific condition handling semantics
If language-specific semantics are established within a stack frame, they are honored. Of course, the language-specific handling mechanisms act only on those conditions for which the language has a defined action. The language percolates all other conditions by passing them on to the next condition handler.

If a condition is unhandled after the stack is traversed, default language-specific and Language Environment condition semantics take over.