Nested Exceptions

A nested exception is an exception that occurs while another exception is being handled.

OS/2 supports nested exceptions because an unhandled exception that occurs in an exception handler should be handled at a higher level-that is, by an ancestor of the procedure that registered the offending handler.

When a nested exception occurs, the EH_NESTED_CALL flag is set in the exception structure to indicate that a nested function call is being made. The normal convention then is for the handler to return immediately without handling the exception if the EH_NESTED_CALL flag is set. Without this flag, it would be easy to create an infinitely recursive situation.

For example, suppose we have the following scenario:

Now suppose that procedure PD causes an exception. The system refers to the current thread's chain of exception handlers.

Because procedure PD has no handler, the system calls HC, the handler for procedure PC, with the EH_NESTED_CALL flag clear. If handler HC returns CONTINUE_SEARCH, the system calls the next handler in the chain, handler HB, again with the EH_NESTED_CALL flag clear.

Now suppose that exception handler HB causes an exception while it is processing the original exception. The call frames for the procedures are arranged in the following order on the stack: