我使用GCC 9.2抛出的任何东西都会被terminate调用,即使它被捕获了。
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
我也尝试过将抛出放入一个函数中,并添加了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,使用远程调试在两个目标处理器上上传和单步执行代码。
发布于 2020-09-04 06:11:28
似乎有一个bug或者异常处理不能在GCC 9.2版本上工作(只有ARM?)编译器。
我尝试了8.3-2019.03 - arm- Linux -gnueabihf -Linux版本的x86编译器,它们工作得很好。除了compile开关之外,不需要进行其他更改。
https://stackoverflow.com/questions/63731226
复制相似问题