www.digitalmars.com         C & C++   DMDScript  

c++.windows.32-bits - Traping divide by zero

I can't figure out how to trap either floating point, or integer
divide by zero.

On some other compilers, I can trap SIGFPE and that does the trick
for both floating point, and for integer divide by zero.  On dmc
and microsoft VC (in this regard, the two compilers seem to act
identically), the expression:
 double d = 8.0/0.0; //does not raise a signal that I can tell.
does nothing but assign inf to d and move on.  However, the
expression:
 int i = 8/0;
causes the program to abort.  I can't figure out how to trap the
error and prevent the abort, or how to trap the floating point
divide by zero.

David
Jan 03 2008