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?
You can catch the base exception class
program_options::errorby reference:Live On Coliru
Printing
Although there's no diagram there is a kind of error reference: https://www.boost.org/doc/libs/1_84_0/doc/html/program_options/reference.html#header.boost.program_options.errors_hpp
The individual types do mention purpose e.g.: "Base class for all errors in the library")