I am trying to set up an exception handler using sigaction. It works well for the first exception. But the sigaction handler is not called after the 1st exception and the pr
Signals and exceptions are not related to each other. What you're using (throwing exceptions from async signal handlers) is only portable between the few compilers that support it, such as GCC and Intel C/C++ with -fnon-call-exceptions
.
That said, what you forgot to do is unblock the signal: when a signal handler is executing, the delivery of the same signal is blocked, and it does not become unblocked when the signal handler is exited through an exception. Change the signal handler as follows:
void SigactionHookHandler( int iSignal, siginfo_t * psSiginfo, void * psContext
{
cout << "Signal Handler Exception Caught: std::exception -- signal : " << iSignal << " from SigactionHookHandler()" << endl;
sigset_t x;
sigemptyset (&x);
sigaddset(&x, SIGSEGV);
sigprocmask(SIG_UNBLOCK, &x, NULL);
throw std::exception();
}
Standard C++ says nothing about signals, or about how they interact with exceptions. What you are trying to do will be completely specific to the OS platform you are using and possibly the specific compiler you compile your code with.