how to disable floating point exceptions?
how to disable floating point exceptions?
- Subject: how to disable floating point exceptions?
- From: Rua Haszard Morris <email@hidden>
- Date: Thu, 16 Aug 2007 09:47:27 +1200
Is it possible to prevent an application crashing on EXC_ARITHMETIC
(e.g. divide by zero) on i386?
I believe that on PPC there is no crash, and no crash when running in
rosetta (this is somewhat beside the point however).
I have tried installing a signal handler using sigaction, and calling
sigaction specifying SIG_IGN to hopefully ignore the exception (see
code snippet below).
The signal handler approach mostly worked, in that my signal handler
was called, but the crash behaviour remained, in that I wasn't able
to call an emergency exit function from within the signal handler;
the app didn't disappear, but wasn't responsive, and either the call
to emergency quit wasn't effective or didn't happen. Also the "App
has unexpectedly quit" crash handler kicked in as per normal.
SIG_IGN didn't seem to have any effect different than normal
exception behaviour (it must mean that only the _app_ ignores the
signal).
Does anyone know how to intercept floating point exceptions when
running on i386 such that the program flow can be resumed enough to
inform the user and quit the app a little more gracefully?
Is my problem that I don't know how to (or can't) circumvent
crashreporter handling the exception?
any hints would be greatly appreciated
Rua HM.
// example code. acknowledgements to http://gcc.gnu.org/ml/gcc-help/
2002-04/msg00003.html
void fpeHandler (int, siginfo_t*, void*)
{
FAIL( "Floating-point exception" ); // essentially an assert(false),
string appears in console successfully
CleanUpAndExit(false); // quit-now-but-please-don't-crash function,
is called, but app doesn't quit nicely
}
void initFpe()
{
struct sigaction sa;
sa.sa_flags = SA_SIGINFO;
sa.sa_sigaction = fpeHandler; // this results in my callback (sig
handler) being called, but crashreporter still takes over
sigaction (SIGFPE, &sa, 0);
}
main()
{
....
initFpe();
// run app etc
// perform complex sequence of actions leading to divide-by-zero ...
...
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden