c++ - c++ try try catch的所有命中命中终止于C++ 11 14和17

标签 c++ try-catch terminate throw

我一直在使用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编译器,它们工作得很好。除了编译开关以外,不需要其他任何更改。
https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-a/downloads

关于c++ - c++ try try catch的所有命中命中终止于C++ 11 14和17,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63731226/

相关文章:

c++ - 添加新阵列会改变以前的阵列吗?

c++ - 创建一个易于维护的复制构造函数

javascript - Javascript 中 'nested' try/catch 语句的困惑

c++ - 一个类使用另一个类的方法c++

java - catch语句的顺序?

python - 无法在多处理 python ( linux ) 中终止进程

android-studio - 如何在 Android Studio 中停止应用程序

c++ - 指向数组 c++ 的指针

c++ - 从 unique_ptr 初始化 unique_ptr const 引用

Perl 根据用户输入结束循环/代码块 (!die/exit)