[LCP]Problem with SIGFPE
Jesús Peco
peco at iit.upco.es
Fri Feb 28 16:02:53 UTC 2003
I would be very pleased if you could help tell
me what's wrong with the code below. I'm trying
to catch SIGFPE but without results.
I have a debian woody 3.0 on a PC
with libc6 2.2.5-11.2
and g++ 3.0.4
Thank you very much.
#include <iostream>
#include <csignal>
void catchFPE(int) {
std::signal(SIGFPE, catchFPE);
std::cerr << "Float Point Exception. Exit..." << std::endl;
std::exit(1);
}
int main()
{
double a=20.0, b=3.0, c;
std::signal(SIGFPE, catchFPE);
while(b>-3.0) {
std::cout << a << "/" << b << "=" << a/b << std::endl;
b=b-1.0;
c=a/b;
}
return 0;
}
I have also tried de "equivalent" in "C" with no results.
#include <stdio.h>
#include <signal.h>
void handler(int sig);
int main()
{
double i;
signal(SIGFPE, handler);
....
}
More information about the linuxCprogramming
mailing list