这是我所说的代码部分。
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
编辑:当没有例外时,解析和一切工作正常。
这可能与 RTTI(运行时类型信息)问题有关,类似于Google 地图的此问题 https://code.google.com/p/gmaps-api-issues/issues/detail?id=9567 or 这个问题关于SO https://stackoverflow.com/questions/21737201/problems-throwing-and-catching-exceptions-on-os-x-with-fno-rtti.
确保 Boost 和你的代码编译时没有fno-rtti
flag.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)