I have this short c program that deliberatly causes a SIGPFE and tries to handle it:
#include <stdio.h>
#include <signal.h>
void catch_floating_point_error(int signal_number) {
printf("I caught a floating point error\n");
}
int main() {
signal(SIGFPE, catch_floating_point_error);
for (signed int i = -3; i<=3; i++) {
printf ("30 / %d = %d\n", i, 30/i);
}
}
When I compile and execute this program, it prints
30 / -3 = -10
30 / -2 = -15
30 / -1 = -30
I caught a floating point error
I caught a floating point error
I caught a floating point error
...
until I terminate the process with ctrl-c.
I expected that the program would resume with the execution one instruction after the instruction causing the FPE after executing the signal handler catch_floating_point_error
.
This is apparently not the case. It seems that the program is re-doing the failing instruction again.
So, how can I skip the failed intstruction when I was notified that I had a SIGFPE?