Condition occurs with signal handler present

Figure 1 contains a simple example of a C application in which y = a/b is a mathematical operation. signal (SIGFPE, c_handler) is a signal invocation that registers the routine c_handler() and gives it control if a floating-point divide exception occurs.

Figure 1. C condition handling example
/*Module/File Name:  EDCCSIG  */
/**********************************************************************/
/* A routine with a C/370 condition handler registered.               */
/**********************************************************************/

#include <stdio.h>
#include <signal.h>

#ifdef __cplusplus
extern "C" {
#endif
   void c_handler(int);
#ifdef __cplusplus
}
#endif
int main(void) {
  int a=8, b=0, y;
  /* .
     .
     . */
  signal (SIGFPE, c_handler);
  /* .
     .
     . */
  y = a/b;
  /* .
     . */
}

void c_handler(int i)
{
   printf("handled SIGFPE\n");
  /* .
     . */
   return;
}
If b = 0, a floating-point divide condition occurs. Language Environment condition handling begins:
  • The enablement step occurs.
    • If Table 1 indicates that floating-point divide is a masked exception, the exception is ignored. The floating-point divide is not a masked exception, however.
    • If SIG_IGN is specified for the SIGFPE exception in any of the three examples, then the SIGFPE exception is ignored. However, this does not occur.

    The floating-point divide condition is enabled and enters the condition step of condition handling.

  • If a debug tool is present, it receives control.
  • If a user-written condition handler is registered by CEEHDLR for that stack frame, it receives control.
If none of the above takes place, the condition manager gives the C signal-handler control. This handler in turn invokes c_handler() as specified in the signal() function in Figure 1. Control is then returned to the instruction following the one that caused the condition.