Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting floating point exceptions into C++ exceptions

Is it possible to convert floating point exceptions (signals) into C++ exceptions on x86 Linux?

This is for debugging purposes, so nonportability and imperfection is okay (e.g., if it isn't 100% guaranteed that all destructors are called).

like image 799
Geoffrey Irving Avatar asked Sep 17 '08 17:09

Geoffrey Irving


1 Answers

If your C++ standard library implementation supports the TR1 functions fetestexcept, feraiseexcept and feclearexcept (mine doesn't yet so I can't test this) you can detect five kinds of floating point errors and then you can throw whatever exceptions you want.

See here for a description of these functions.

I also recommend section 12.3, "Managing the Floating Point Environment," of the book The C++ Standard Library Extensions: A Tutorial and Reference by Pete Becker, ISBN-13: 9780321412997, for an excellent description of these functions with sample code.

alt text

like image 132
jwfearn Avatar answered Sep 24 '22 03:09

jwfearn