gpt4 book ai didi

c++ - _matherr 不会在发布版本中被调用(C++ Builder 2007)

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:33:35 24 4
gpt4 key购买 nike

我的代码可能存在浮点溢出,无法通过检查函数参数来管理。我必须定义 _matherr 并从其中抛出异常,以便调用者有机会管理问题。

有些奇怪:在 Debug 版本中,_matherr 按预期被调用,但在 Release 中没有。我使用 CodeGear C++ Builder 2007。在 MSVC 2010 下,处理程序工作正常,但我需要整个应用程序的 VCL 功能。谷歌搜索只提供有关 _matherr 无法在 DLL 中工作的消息(从文档中得知)。

我的问题是:_matherr 在 Release 中不起作用的原因可能是什么?

// One of the methods with overflows.
double DoubleExponential::F(double x) const
{
try
{
double y=pow(fabs(x),a);
return 0.5 + sign(x)*G(y,1/a)/(2*G(1/a));
}
catch(PowExpOverflow)
{
return 0.5;
}
}

// Exception.
struct PowExpOverflow {};

int _matherr (struct _exception *a){
Application->MessageBox("Inside custom _matherr", "", MB_OK);
if (a->type == OVERFLOW)
if (!strcmp(a->name,"pow") ||
!strcmp(a->name,"powl") ||
!strcmp(a->name,"exp") ||
!strcmp(a->name,"expl"))
{
throw PowExpOverflow();
}
return 0;
}

最佳答案

问题是由于我在发布版本 (description) 中使用的动态 RTL 中的错误。该错误在我使用的 IDE 版本中未修复,因此唯一可行的解​​决方案是升级到更高版本。尽管如此,有一个清晰的解释还是很有帮助的。

关于c++ - _matherr 不会在发布版本中被调用(C++ Builder 2007),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8851053/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com