小编Ale*_*sev的帖子

为什么在 macOS M1 环境中 `std::invalid_argument` 没有被 no-rtti 捕获?

今天我在 C++ 中捕获异常时遇到了一个奇怪的行为,有人可以向我解释一下吗?代码片段

#include <iostream>
#include <string>
#include <exception>


int main() {
  try {
    std::stod("notanumber");
  } catch (const std::invalid_argument&) {
    std::cerr << "std::invalid_argument" << std::endl;
  } catch (const std::out_of_range&) {
    std::cerr << "std::out_of_range" << std::endl;
  } catch (const std::exception&) {
    std::cerr << "Caught by ancestor" << std::endl;
  } catch (...) {
    auto ptr = std::current_exception();
    auto type = __cxxabiv1::__cxa_current_exception_type();
    std::cerr << type->name() << std::endl;
    std::cerr << "..." << std::endl;
  }
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

写入输出

St16invalid_argument
...
Run Code Online (Sandbox Code Playgroud)

环境详情

C++ 14, disabled …
Run Code Online (Sandbox Code Playgroud)

c++ macos std rtti c++14

13
推荐指数
0
解决办法
378
查看次数

标签 统计

c++ ×1

c++14 ×1

macos ×1

rtti ×1

std ×1