Dear All : I use c language in mac os ,and i want to catch the exception SIGFPE.
the question is that i use unix signal function to catch the SIGBUS. of couse it was catched and the application is going on. But the system also get the exception and give me the log
PID: 1112
Thread: 0
Exception: EXC_ARITHMETIC (0x0003)
Codes: EXC_I386_DIV (divide by zero) Thread 0 Crashed:
0 test 0x00002ac8 test(int, int) + 148 (main.cpp:40)
1 test 0x00002b46 main + 82 (main.cpp:52)
2 test 0x00002346 _start + 228 (crt.c:272)
3 test 0x00002261 start + 41
it's a sample test function. can anyone help me? test code is blow:
#include <iostream>
#include <sys/signal.h>
#include <setjmp.h>
#include <sys/signal.h>
typedef void (*sighandler_t)(int);
static sigjmp_buf jmpbuf;
void sig_action(int i)
{
printf("signal: %d\n", i);
siglongjmp(jmpbuf, 1);
return ;
};
int test (int m ,int j)
{
int tt2 = 0;
sighandler_t old ;
old = signal(SIGFPE, sig_action);
if(sigsetjmp(jmpbuf, 1))
{
goto E1;
}
//raise(SIGFPE); // if I use raise to send the exception, everything is ok.
tt2 += m/j;
E1:
old = signal(SIGFPE, old);
return tt2;
}
int main (int argc, char * const argv[])
{
int i = 0, value = 0 ;
for (i = 0; i< 5; i++)
{
printf("i=%d\n",i);
value = test(9, 0);
printf("i2=%d\n",i);
}
std::cout << "Hello, World!\n"<<value<<"i:"<<i;
return 0;
}
the question is that i use unix signal function to catch the SIGBUS. of couse it was catched and the application is going on. But the system also get the exception and give me the log
PID: 1112
Thread: 0
Exception: EXC_ARITHMETIC (0x0003)
Codes: EXC_I386_DIV (divide by zero) Thread 0 Crashed:
0 test 0x00002ac8 test(int, int) + 148 (main.cpp:40)
1 test 0x00002b46 main + 82 (main.cpp:52)
2 test 0x00002346 _start + 228 (crt.c:272)
3 test 0x00002261 start + 41
it's a sample test function. can anyone help me? test code is blow:
#include <iostream>
#include <sys/signal.h>
#include <setjmp.h>
#include <sys/signal.h>
typedef void (*sighandler_t)(int);
static sigjmp_buf jmpbuf;
void sig_action(int i)
{
printf("signal: %d\n", i);
siglongjmp(jmpbuf, 1);
return ;
};
int test (int m ,int j)
{
int tt2 = 0;
sighandler_t old ;
old = signal(SIGFPE, sig_action);
if(sigsetjmp(jmpbuf, 1))
{
goto E1;
}
//raise(SIGFPE); // if I use raise to send the exception, everything is ok.
tt2 += m/j;
E1:
old = signal(SIGFPE, old);
return tt2;
}
int main (int argc, char * const argv[])
{
int i = 0, value = 0 ;
for (i = 0; i< 5; i++)
{
printf("i=%d\n",i);
value = test(9, 0);
printf("i2=%d\n",i);
}
std::cout << "Hello, World!\n"<<value<<"i:"<<i;
return 0;
}