繁体   English   中英

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

[英]_matherr does not get called in release build (C++ Builder 2007)

我有一个可能存在浮点溢出的代码,无法通过检查函数的参数进行管理。 我必须定义_matherr并从其内部引发异常,以使调用者有机会管理该问题。

有点奇怪:在Debug版本中,_matherr按预期方式被调用,但在Release中则未被调用。 我使用CodeGear C ++ Builder2007。在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版本中修复,因此唯一可行的解​​决方案是升级到更高版本。 不过,有一个清晰的解释会很有帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM