clang try catch fails

帅比萌擦擦* 提交于 2020-04-10 07:58:09

问题


Here is the portion of code I speak about.

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

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

Just for the seek of details , I m using boost program_options to parse a configuration file. An exception is raised by boost since I put an option in the file that is unrecognized.

There is a problem with Clang not catching this exception. Basically I only see in the output

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

Here is my clang version:

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

EDIT: When there is no exception, the parsing and everything works fine.


回答1:


This could be related to the RTTI (Run Time Type Information) issue that is similar to this issue with GoogleMaps or this question on SO.

Make sure that Boost and your code are compiled without fno-rtti flag.




回答2:


For me the solution was to remove the linker flags "-Wl,-no_compact_unwind" (Catalina, Apple clang version 11.0.0 (clang-1100.0.33.17))



来源:https://stackoverflow.com/questions/39705639/clang-try-catch-fails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!