Re: C++Builder and Delphi Exceptions
"Rory Daulton" <[email protected]>
| Newsgroups | gmane.comp.lang.delphi.programming |
|---|---|
| Message-ID | <001401c353c9$e8fecb10$6401a8c0@laptop> |
Mihai, > I am doing a research project in C++Builder 5.0 and > I'm using large numbers. > > I have some problems with exception handling. > > If I perform some operations that overflow the > capacity of the double data type I usually get an > EOverflow exception. > > But, sometimes the variables that stores the results > are filled with some C++Builder constants (such as NAN > or INF) and no exception is thrown. But, if I use > these > variables (filled with NAN or INF) I get an error and > my application stops. > > My question is how could I handle all these exception > in a uniform manner? I wrote several test functions > that check whether the variables contain the NAN and > INF constants, but this significantly slows down my > application. So I don't want to use this functions > anymore, but I need some mechanisms for preventing > such situations. My experience is with Delphi, not BCB, but I can give you a few thoughts. First, an overflow of the Double type may not result in an EOverflow exception. If the FPU/NPU has encountered an underflow or denormal since it was last reset, Delphi gives an EInvalidOp instead of EOverflow. (I don't know what BCB does.) I suggest you test for EMathError instead, since this catches all overflow exceptions. You should determine just how those NANs and INFs are getting into your data. They do not easily result from normal operations. I believe that the most common ways they result are from the FPU control word changed to ignore overflow and other errors, constants (which means *you* put them in your program), or from floating fields in a database. You could probably save time by checking these special values only at input (and ensuring the FPU control word is not changed). How complicated is your test for INF/NAN? If you don't need to distinguish between them, there is a simple test for "special" values for a double variable: if (Int64(DblVariable) and $7FF00000) = $7FF00000 then ... HTH. Rory Daulton [email protected] Campus Crusade for Christ --- [This E-mail scanned for viruses by Declude Virus and Nmax "Your MAXimum Connection!"] [This E-mail scanned for spam by Declude JunkMail and Nmax "Your MAXimum Connection!"] ------------------------ Yahoo! Groups Sponsor ---------------------~--> Buy Toner for Your Printer or Fax at LaserTonerSuperstore.com-Save 55%! We have your brand: HP, IBM, Canon, Xerox, Apple and many more for less! http://www.LaserTonerSuperstore.com http://us.click.yahoo.com/YmQqWC/qicGAA/ySSFAA/i7folB/TM ---------------------------------------------------------------------~-> CodeCoffer - new Delphi code protection Tool! http://www.delphicollection.com/public/CodeCoffer.htm --------------------------------------------------------------- Unsubscribe:[email protected] List owner:[email protected] --------------------------------------------------------------- Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/