ILE C/C++ Programmer's Guide

When to Use the Signal Handler

For portable code across multiple platforms, use only the signal() function to handle exception. ILE condition handlers should be used if a consistent mechanism for handling exceptions across ILE enabled languages is required. If portability across ILE-enabled platforms is a concern, then ILE condition handlers and the signal() function can be used. Otherwise, all three types of handlers may be used. See Using Both C/C++ Signal and ILE Exception Handlers.

Note:

Stream I/O functions trap the SIGIO signal, which is sent when normal data, OOB data, error conditions, or just about anything happens on any type of socket. Signal handlers that are registered for SIGIO are not called for exceptions that are generated when processing stream files.

Using the signal() function will always handle the exception implicitly (unless the signal action is SIG_DFL, in which case it would percolate the exception); with direct monitor handlers you either have to specify a control action that will implicitly handle the exception (_CTLA_HANDLE, _CTLA_HANDLE_NO_MSG, _CTLA _IGNORE, or _CTLA_IGNORE_NO_MSG), or you have to handle the exception explicitly within the handler function (when the control action _CTLA_INVOKE is specified), using either QMHCHGEM or an ILE condition handling API.

Note:
Direct monitors are usually the fastest handlers.

The HLL-specific handler, which is the signal handler in ILE C, is global. It is enabled for all function calls in the activation group the signal() function is called. In ILE, condition handlers and direct monitor handlers are scoped to the function that enables them or until they are disabled in that function.

The following example illustrates that if you do not want to change the state of a signal handler when the signal function returns, then you must manage the state of the signal handler explicitly.

Figure 179. ILE C Source to Manage the State of a Signal Handler




#include <signal.h>
void f(void)
{
void (*old_state)(int);
/* Save old state of signal action */
old_state = signal(SIGALL,handlr);
/* Other code in your application */
/* Reset state of signal */
signal(SIGALL,old_state);
}

ILE condition handlers and direct monitor handlers do not have this requirement because they are not global handlers.


[ Top of Page | Previous Page | Next Page | Table of Contents ]