Restrictions on Using the setjmpx Kernel Service
Process and interrupt handler routines registering exception handlers with the setjmpx kernel service must not return to their caller before removing the saved jump buffer or buffers from the list of jump buffers.
A saved jump buffer can be removed by invoking the clrjmpx kernel service in the reverse order of the setjmpx calls. The saved jump buffer must be removed before return because the routine's context no longer exists once the routine has returned to its caller.
If, on the other hand, an exception does occur (that is, the return code from setjmpx kernel service is nonzero), the jump buffer is automatically removed from the list of jump buffers. In this case, a call to the clrjmpx kernel service for the jump buffer must not be performed.
Care must also be taken in defining variables that are used after the context save (the call to the setjmpx service), and then again by the exception handler. Sensitive variables of this nature must be restored to their correct value by the exception handler when an exception occurs.
Exception handling is concluded in one of two ways. Either a registered exception handler handles the exception and continues from the saved context, or the default exception handler is reached by exhausting the stack of jump buffers.