【发布时间】:2017-02-03 23:06:07
【问题描述】:
这是我所说的代码部分。
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
编辑:当没有异常时,解析和一切正常。
【问题讨论】:
-
你有什么版本的 boost?也许你使用 catch(std::exception&) 会更好运
-
提升 1.55。一切都是用 Clang 针对 libC++ 编译的。是的,我在提交问题之前尝试了 catch(std::exception&) 但它没有用。
-
这在 boost 和 exe 针对不同的标准库编译时很常见(我知道您提到了这一点,但请再次检查)。
-
@RichardHodges 谢谢。我会仔细检查。但如果是这种情况,它不应该在链接时抛出错误吗?
-
链接器不检查异常 ABI 兼容性。 C++ 需要对内部实现进行大量标准化,这会影响链接由不同编译器为 rtti、异常 ABI 和 mangle 构建的不同模块(现在,当您需要通过一个编译器重建所有库时,这很痛苦。希望他们会为这些东西带来一些标准,而不是只是语法糖。
标签: c++ exception-handling clang