问题描述
使用GCC 9.2抛出的任何内容,即使被捕获,我也会不断被要求终止。
terminate called after throwing an instance of 'char const*'
terminate called recursively
我已经测试了-std = c ++ 17,-std = c ++ 14,-std = c ++ 11
示例测试:
#include <iostream>
int main()
{
try
{
throw "not found";
}
catch(...)
{
std::cout << "test" << std::endl;
}
return 0;
}
如果我使用Visual Studio或多个在线编译器进行编译,它不会失败。 例: https://repl.it/languages/cpp https://www.onlinegdb.com/online_c++_compiler
我也尝试过将throw放入函数中并添加noexcept(false),但这也失败了。示例:
#include <iostream>
void foo() noexcept(false)
{
throw std::runtime_error( "test1" );
}
int main()
{
try
{
foo();
}
catch(...)
{
std::cout << "test2" << std::endl;
}
return 0;
}
编辑:
系统信息:
我正在使用9-2020-q2-update-arm-linux-none-gnueabihf。
基本上,安装程序是Linux x86作为我的主计算机,可以针对ARM Cortex-A处理器进行交叉编译。我正在测试的处理器是RaspBerry Pi 4和BeagleBone Black。
该代码可正确编译并在目标处理器上正常运行,除非遇到异常。在这一点上,任何命中都会终止。
我使用Eclipse作为IDE,使用远程调试在两个目标处理器中的任何一个上载并逐步执行代码。
解决方法
似乎在GCC 9.2版(仅ARM?)编译器上有错误或异常处理不起作用。
我尝试使用8.3-2019.03版-arm-linux-gnueabihf-Linux x86编译器,它们工作得很好。除了编译开关,不需要其他任何更改。