捕获浮动异常 [英] Catching floating exceptions

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

问题描述

我无法捕获浮动异常(例如除以0或0/0)

使用stdexcept中定义的标准异常。什么是b / b
推荐的捕获此类异常的方法?


谢谢,



I am unable to catch floating exceptions (e.g. divide by 0 or 0/0)
using the standard exceptions defined in stdexcept. What is the
recommended way to catch such exceptions?

Thanks,
Song

推荐答案

us **** @ sta.samsung.com 写道:

我无法捕捉浮动异常(例如除以0或0/0)

使用在stdexcept。

建议的方法是什么来捕获这些例外?
I am unable to catch floating exceptions (e.g. divide by 0 or 0/0)
using the standard exceptions defined in stdexcept. What is the
recommended way to catch such exceptions?



你不能。至少在标准C ++中,可能存在平台特定扩展,但硬件生成的陷阱与

C ++语言异常不同。

-

Ian Collins。

You can''t. At least not in standard C++, there might be platform
specific extensions, but hardware generated traps are not the same as
C++ language exceptions.

--
Ian Collins.


< us **** @ sta.samsung.comwrote in message

新闻:11 ********************** @ p77g2000hsh.googlegr oups.com ...
<us****@sta.samsung.comwrote in message
news:11**********************@p77g2000hsh.googlegr oups.com...

>我无法捕获浮动异常(例如除以0或0/0)

使用stdexcept中定义的标准异常。

建议的方法是什么来捕获这些异常?
>I am unable to catch floating exceptions (e.g. divide by 0 or 0/0)
using the standard exceptions defined in stdexcept. What is the
recommended way to catch such exceptions?



问题是没有抛出异常?整数除以零将

抛出一个系统错误,一个浮点除以错误应返回

无穷大或负无穷大。考虑下面的程序我刚刚一起扔了

。可能有更好的方法,但我只是不确定它是什么。


#include< iostream>

#include< cfloat> ;


int main()

{


浮点数零= 0.0f;

float Inf = 5.0f / Zero;

float NegInf = -5.0f / Zero;


float x = -5.0f;

float y = 0.0f;

float z = x / y;


std :: cout<< z<< " \ n";

if(z == Inf || z == -Inf)

std :: cout<< 除以零(无穷大)。 << " \ n";


返回0;

}

Is the problem that no exception is thrown? An integer divide by zero will
throw a system error, a floating point divide by error should return
infinity or negative infinity. Consider the following program I just threw
together. There is probably a better way, but I''m just not sure what it is.

#include <iostream>
#include <cfloat>

int main()
{

float Zero = 0.0f;
float Inf = 5.0f / Zero;
float NegInf = -5.0f / Zero;

float x = -5.0f;
float y = 0.0f;
float z = x/y;

std::cout << z << "\n";
if ( z == Inf || z == -Inf )
std::cout << "Division By Zero (infinity) " << "\n";

return 0;
}


us****@sta.samsung.com 写道:
us****@sta.samsung.com wrote:

我无法捕获浮动异常(例如除以0或0/0)

使用stdexcept中定义的标准异常。

建议的方法是什么来捕获这些异常?
I am unable to catch floating exceptions (e.g. divide by 0 or 0/0)
using the standard exceptions defined in stdexcept. What is the
recommended way to catch such exceptions?



你应该做的第一件事是决定你是用C ++编程

还是用D.

The first thing you should do is decide whether you are programming in C++
or in D.


这篇关于捕获浮动异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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