Re: Handling Floating Point Exception in VC++ 6.0
"SONET" <SONET@discussions.microsoft.com> wrote in message
news:309A110A-6060-49FD-B162-B17CB7C27398@microsoft.com...
I've been trying to handle floating point exceptions but I am having some
problems.
Basically I am able to catch the exception with the catch(...), I wrote a
class that should be thrown but it is not working.
the problem is that it never hits the FloatException catch, and it never
executes the FloatExceptionHandler. it does get caught in the catch(...)
which didn't do before I wrote the code.
Hi,
Here are a few tidbits I've picked up over time that I can add (if anyone
left any of this info out):
1. The FPU has a (status) register in it that it updates after each
operation (same as CPU status)
2. The FPU has a second register that masks the status register to
SOMETHING LIKE an interrupt request
line feeding into the CPU.
The MASK register is usually set with 0 (or ~0 ?) such that nothing gets
out, This is for performance (easily seen).
Here's a very imporant point:
3. The 'IRQ' line feeding into the CPU is only POLLED by the CPU -- the
polling is performed AT THE BEGINNING
OF EACH FPU OPERATION.
4. If the CPU discovers an un-masked error condition the line, it raises a
WIN32 exception.
This means the Win32 exception usually appears on the NEXT LINE OF CODE.
For example:
double x=0;
int main()
{
double y = x/x;
puts ("Hello world");
double x = x+x; //Win32 exception raised
return 0;
}
Example:
inline unsigned int FPU_EXCEPTION_ENABLE_MASK (unsigned int x) {return
(~(x))&0x0000001f;}
//*************************************************************************************************void PossiblyAdjustFPUMask() { if (!g_fEnableInvalidOperationTrap) return; _clearfp ();//in float.h: //_EM_INVALID represents NaN creation _controlfp (FPU_EXCEPTION_ENABLE_MASK(_EM_INVALID), _MCW_EM); }*************************************************************************************************void PossiblyRestoreFPUMask() { if (!g_fEnableInvalidOperationTrap) return; _clearfp (); _controlfp (_CW_DEFAULT, ~0); }--------------------------------------------I think others have mentioned that these are Win32Exceptions so you'll wantto enable *all* Win32 exceptions before running your program. You can use a__try / __except block or try/catch(...) and you should see these exceptionscome out as specified.- Alan Carre