doneDad
asked on
How can I turn on hardware execptions and trap them?
How can I turn on hardware exceptions? The test procedure of a cacluation library tries to force a floating point exception by throwing a whole slew of bogus numbers at the calculation functions. I want to trap, and find instances where this test procedure is successful in causing the calculation library to do something which is ordinarily a floating point exception; i.e. divide by zero, sqrt(-1), log(-100), asin (5), etc. etc.
Is there a way to turn these on, and for the test program to detect their occurrence. I just got bit by a divide by zero problem that was in the code and didn't show up until the code was run on another platform (the client's platform of course). I'd like to trap these errors on my system, MS Visual C++ .NET (currently 2003), in test mode, before the client sees them. Thanks in advance.
Is there a way to turn these on, and for the test program to detect their occurrence. I just got bit by a divide by zero problem that was in the code and didn't show up until the code was run on another platform (the client's platform of course). I'd like to trap these errors on my system, MS Visual C++ .NET (currently 2003), in test mode, before the client sees them. Thanks in advance.
ASKER
Thanks for the info, this looks promising. I'll try this out this evening. The System.DivideByZeroExcepti on . . . et al look like managed code exceptions types. Are there similar types for unmanaged exceptions? Will plain old std::execption work?
I don't think you can handle using std::exception
It was a specific design decision of C++ not to handle divide-by-zero; So you must check your divisors yourself, or discover if your hardware maps divide-by-zero onto some other kind of exception and catch that. It's fairly easy to discover the latter. Just put a try {} catch (...) {} around a divide by zero.
It was a specific design decision of C++ not to handle divide-by-zero; So you must check your divisors yourself, or discover if your hardware maps divide-by-zero onto some other kind of exception and catch that. It's fairly easy to discover the latter. Just put a try {} catch (...) {} around a divide by zero.
ASKER
Well, I'm not even getting that far. I have VC++ 7.0 (2002) and VC++7.1 (2003) and neither will accept /fp as a compiler options. Neither help file lists /fp as an option. Am I out of luck here? Is there some special magic that you have to use?
If I do a catch (...) how do I discover what has been thrown, since I don't have a variable name to work with?
If I do a catch (...) how do I discover what has been thrown, since I don't have a variable name to work with?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
We'll be upgrading to MSVC++ 2005 soon, hoefully the /fp option will be there and we'll be able to use that option at that time. Until then, we'll simply have to test the resulting calcuation values for NAN and infinity. I have found a librarty function to do that, _finite (). It checks (supposedly) for both inifitiy and NAN.
Many thanks for your help.
Many thanks for your help.
http://msdn2.microsoft.com/en-us/library/e7s85ffb.aspx
2. Have your code inside try, catch blocks and handle the Arithmetic exceptions.
System.ArithmeticException
System.DivideByZeroExcepti
System.NotFiniteNumberExce
System.OverflowException
Please refer to
http://msdn2.microsoft.com/en-us/system.arithmeticexception.aspx
for more info.