将浮点异常转换为C ++异常 [英] Converting floating point exceptions into C++ exceptions
问题描述
是否可以在x86 Linux上将浮点异常(信号)转换为C ++异常?
Is it possible to convert floating point exceptions (signals) into C++ exceptions on x86 Linux?
这是为了调试目的,因此非可移植性和不完善,如果不是100%保证所有析构函数都被调用)。
This is for debugging purposes, so nonportability and imperfection is okay (e.g., if it isn't 100% guaranteed that all destructors are called).
推荐答案
如果你的C ++标准库实现支持TR1函数
fetestexcept
, feraiseexcept
和 feclearexcept
我还没有,所以我不能测试这个)你可以检测五种浮点错误,然后你可以抛出任何异常你想要的。
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.
请参阅此处介绍这些功能。
我还建议Pete Becker,ISBN-13:9780321412997中的 The C ++ Standard Library Extensions:A Tutorial and Reference 的第12.3节管理浮点环境使用示例代码非常好地描述这些函数。
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.
这篇关于将浮点异常转换为C ++异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!