将浮点异常转换为C ++异常 [英] Converting floating point exceptions into C++ exceptions

查看:156
本文介绍了将浮点异常转换为C ++异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将浮点异常(信号)转换为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.

请参阅这里,以了解这些功能的描述。

See here for a description of these functions.

我还推荐Pete Becker(ISBN-13:9780321412997)的书籍C ++标准库扩展:教程和参考一书的第12.3节管理浮点环境一个exc使用示例代码对这些功能的描述。

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 http://ak.buy.com/db_assets/prod_images/225/202452225.jpg

这篇关于将浮点异常转换为C ++异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆