#include #include #include #include using namespace std; static sigjmp_buf SAVE_ENV; void FPEHandler(int signal) { cerr << "I had a FPE " << endl; // raise(SIGFPE); siglongjmp(SAVE_ENV,1); return; } const int START = -5; const int STOP = 5; int main() { struct sigaction action; sigset_t set; sigemptyset(&set); action.sa_handler = FPEHandler; action.sa_mask = set; action.sa_flags = 0; sigaction(SIGFPE, &action, nullptr); int i; i = START; while (i < STOP) { if (1 == sigsetjmp(SAVE_ENV,1)) { cout << "Fixing I. " << endl; i++; } cout << "7/" << i << " = " ; cout << 7/i << endl; sleep(1); i++; if (i == STOP) { i = START; } } return 0; }