I am trying to understand how signal handling works so I decided to handle division by zero another way. The program should request input until division by zero does not occur. However, my handler is ignored after the first jump and the division is handled by the system. Why does this happen?
#include <stdio.h>
#include <signal.h>
#include <setjmp.h>
jmp_buf env;
void handler(int sig) {
printf("Invalid input , try again\n");
longjmp(env , 1);
}
int main() {
signal(SIGFPE , handler);
int x , y;
setjmp(env);
scanf("%d%d" , &x , &y);
printf("%d\n" , x / y);
}