Stupid question (but I don't find anything on boost.org): how do I catch exceptions from boost::program_options? Invoking
#include <boost/program_options.hpp> #include <iostream> int main(int argc, char** argv){ bool opt; namespace bpo = boost::program_options; bpo::options_description options("Allowed options"); options.add_options() ("opt", bpo::bool_switch(&opt)); bpo::variables_map options_vm; try { bpo::store(bpo::parse_command_line(argc, argv, options), options_vm); bpo::notify(options_vm); } catch(const std::exception &e){ std::cerr << e.what() << std::endl; return 1; } return 0; } with any option but --opt yields
libc++abi: terminating due to uncaught exception of type boost::wrapexcept<boost::program_options::unknown_option>: unrecognised option '--optnsdf' Why doesn't catch(const std::exception &e) catch the exception? How do I properly catch catch(const boost::wrapexceptboost::program_options::unknown_option& e)is not intended, also because there can be other program options-related exceptions, such asboost::wrapexceptboost::program_options::invalid_command_line_syntax`, and probably others.
Is there any class hierarchy for boost program options exceptions available online?
std::exception. As for how, the error message tells you exactly what exception gets thrown.catch(...).