2016-09-26 82 views
7

這是我說的代碼部分。鐺嘗試catch失敗

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來解析配置文件。由於我在無法識別的文件中添加了一個選項,因此引發了異常。

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 

看到這裏是我的鐺版本:

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 

編輯:當沒有例外,解析和一切工作正常。

+2

你有什麼版本的boost?也許你有更好的運氣使用catch(std :: exception&) – Trevir

+0

boost 1.55。所有東西都是用Clang和libC++編譯的。是的,我提交問題之前嘗試趕上(std :: exception&),但它沒有工作。 –

+1

當boost和exe針對不同的標準庫編譯時(我知道你提到過這個,但是再次檢查),這是很常見的。 –

回答