漏点异常的等级是什么? [英] What is the class of a loating point exception ?

查看:118
本文介绍了漏点异常的等级是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Stroustrup中,他谈到了一个MathErr类,你可以用来捕获
浮点异常。

它不存在,至少在Visual C ++中不存在


我可以使用catch(...)来捕获FP异常,但是我很难找到我正在捕捉的类是什么的b $ b。 />
我想知道如何以比

catch(...)更优雅的方式捕获它们,然后在寄存器中调整以猜测问题。


TIA

EoG

In Stroustrup he talks of a MathErr class that you can use to catch
floating point exceptions.
It doesn''t exist, at least not in Visual C++

I can catch FP exceptions using catch(...) but am stumped in finding
out what the class I''m catching is.
I would like to know how to catch them in a more elegant way than
catch(...) and then poling around in registers to guess the problem.

TIA
EoG

推荐答案

2007-03-18 14 :26, Ev********@googlemail.com 写道:
On 2007-03-18 14:26, Ev********@googlemail.com wrote:

在Stroustrup中,他谈到了一个MathErr类,你可以用它来捕获

浮点异常。

它不存在,至少不是在Visual C ++中


我可以使用catch(...)来捕获FP异常但是我很难找到

out the clas我很抓人了。

我想知道如何以比

catch(...)更优雅的方式捕获它们然后在注册以猜测问题。
In Stroustrup he talks of a MathErr class that you can use to catch
floating point exceptions.
It doesn''t exist, at least not in Visual C++

I can catch FP exceptions using catch(...) but am stumped in finding
out what the class I''m catching is.
I would like to know how to catch them in a more elegant way than
catch(...) and then poling around in registers to guess the problem.



一般来说,浮点错误不会在C ++中抛出异常,例如


double i = 0;

double j = 1 / i;


不会抛出异常(但会终止你的应用)。如果你想要在C ++中处理浮点错误,你必须自己检查它们并抛出一个适当的异常。这样做的一种方法是

将float / double封装在一个类中,其接口与dloat /

double相同但执行这些检查。


-

Erik Wikstr?m

In general floating point errors do not throw exceptions in C++, for example

double i = 0;
double j = 1/i;

will not throw an exception (it will however terminate your app). If you
want to handle floating point errors in C++ you have to check for them
yourself and throw an appropriate exception. One way tho do this is to
encapsulate float/double in a class with the same interface as dloat/
double but which performs those checks.

--
Erik Wikstr?m


3月18日下午3:24,Erik Wikstr?m< Erik-wikst ... @ telia.comwrote:
On Mar 18, 3:24 pm, Erik Wikstr?m <Erik-wikst...@telia.comwrote:

一般来说,浮点错误不会在C ++中抛出异常,例如


double i = 0;

double j = 1 / i;


不会抛出异常(但会终止你的应用)。
In general floating point errors do not throw exceptions in C++, for example

double i = 0;
double j = 1/i;

will not throw an exception (it will however terminate your app).



这不是未定义的行为吗?在我的gcc上它只会导致

NaN在cout-ed时打印#INF。

Isn''t it undefined behaviour? On my gcc it does only result in having
NaN that prints #INF when cout-ed.


3月18日, 14:24,Erik Wikstr?m< Erik-wikst ... @ telia.comwrote:
On 18 Mar, 14:24, Erik Wikstr?m <Erik-wikst...@telia.comwrote:

2007-03-18 14:26,EvilOld .. 。@ googlemail.com写道:
On 2007-03-18 14:26, EvilOld...@googlemail.com wrote:

在Stroustrup中,他谈到了一个MathErr类,你可以使用它来捕获

浮点异常。 br />
它不存在,至少不存在于Visual C ++
In Stroustrup he talks of a MathErr class that you can use to catch
floating point exceptions.
It doesn''t exist, at least not in Visual C++


我可以使用catch捕获FP异常(.. 。)但我很难找到我正在捕捉的课程。

我想知道如何以比<更优雅的方式捕捉它们br />
catch(...)然后在寄存器中进行极化以猜测问题。
I can catch FP exceptions using catch(...) but am stumped in finding
out what the class I''m catching is.
I would like to know how to catch them in a more elegant way than
catch(...) and then poling around in registers to guess the problem.



一般来说,浮点错误不会在C ++中抛出异常,例如


double i = 0;

double j = 1 / i;


不会抛出异常(但会终止你的应用)。如果你想要在C ++中处理浮点错误,你必须自己检查它们并抛出一个适当的异常。这样做的一种方法是

将float / double封装在一个类中,其接口与dloat /

double相同但执行这些检查。


-

Erik Wikstr?m


In general floating point errors do not throw exceptions in C++, for example

double i = 0;
double j = 1/i;

will not throw an exception (it will however terminate your app). If you
want to handle floating point errors in C++ you have to check for them
yourself and throw an appropriate exception. One way tho do this is to
encapsulate float/double in a class with the same interface as dloat/
double but which performs those checks.

--
Erik Wikstr?m



我正在使用VC ++,如果你设置了标志,它将在div / 0等上抛出一个异常



我总是按照Erik的建议做的,使用test&扔了,但是很长时间

觉得我可以做得更好。

我*差不多了。

VC ++会抛出一个合适的C ++风格例外(不是Win32 SEH)

但是我没有抓住它。

如果我能确定异常的类型,我可以深入了解

更好。


我的目标是构建一个框架特别防弹的FP代码,

,它允许你以一定的精度搜寻错误。

我在那里,但已撞墙了。

I''m using VC++, and if you set the flags, it will throw an exception
on div/0 et al.
I''ve always done what Erik suggests, using test & throw, but have long
felt I could do a lot better.
I *nearly* have.
VC++ will throw a proper C++ style exception (not a Win32 SEH one)
But I ca''nt catch it.
If I could determine the type of exception I could then drill down
better.

My goal is to build a framework exceptionally bullet proof FP code,
that allows you to hunt down bugs with some precision.
I''m part way there, but have hit a wall.


这篇关于漏点异常的等级是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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