【发布时间】:2020-09-03 20:30:01
【问题描述】:
我不断收到终止调用我使用 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,使用远程调试上传和单步执行任一目标处理器上的代码。
【问题讨论】:
-
请添加有关您获得此结果的系统的详细信息。
-
我已经尝试过
repl.it和 Godbolt,两者都完全按照应有的方式打印出test。您的代码没有问题,但可能与您的编译器标志有关。 -
是的,我也是这么想的。它必须是缺少编译器标志或其他东西。我试过-fexceptions,但这没有用。
-
@user2654735 你能复制它here吗?
标签: c++ try-catch terminate throw