c++ - clang try catch 失败

标签 c++ exception-handling clang

这是我所说的代码部分。

try {
       std::cerr << "first try" << std::endl;
       po::store(po::parse_config_file(ifs, _configFileOptions, false), vm);

} catch(...) {           
       std::cerr << "second try" << std::endl;            
}

只是为了寻求细节,我正在使用 boost program_options 来解析配置文件。由于我在无法识别的文件中放置了一个选项,因此 boost 引发了一个异常。

Clang 没有捕捉到这个异常是有问题的。基本上我只在输出中看到

first try
libc++abi.dylib: terminating with uncaught exception of type boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::program_options::unknown_option> >: unrecognised option 'TestFrequency'
Abort trap: 6

这是我的 clang 版本:

c++ --version
Apple LLVM version 7.3.0 (clang-703.0.31)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

编辑:如果没有异常,解析和一切正常。

最佳答案

这可能与类似于 this issue with GoogleMaps 的 RTTI(运行时类型信息)问题有关或 this question on SO .

确保 Boost 和您的代码在没有 fno-rtti 标志的情况下编译。

关于c++ - clang try catch 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39705639/

相关文章:

c++ - 变量 'temp' 周围的堆栈已损坏

php - 为用户生成的错误抛出异常是否被视为滥用?

c++模板递归双链表错误gcc(但clang++接受)

c++ - 如何统一处理所有错误,包括内部 C 库错误

C++从代码中的不同位置抛出相同的错误消息

templates - C++11:模板参数中的 SFINAE,GCC 与 Clang

c - LLD 和链接描述文件

c++ - 错误 : Innitializer-string for array of chars is too long c++

c++ - 函数返回值的可变性测试

c++ - VS2017调试简单程序时出现访问冲突(RtlActivateActivationContextUnsafeFast)