#include #include #include using namespace std; namespace po = boost::program_options; int main() { try { // Works OK! //throw po::validation_error(po::validation_error::invalid_option_value); // Doesn't work and throw std::out_of_range exception //throw po::validation_error(po::validation_error::invalid_option_value, //"--test"); // Doesn't work as above: std::out_of_range exception //throw po::validation_error(po::validation_error::invalid_option_value, //"--test", ""); // Doesn't work properly. Although it doesn't throw out_of_range // exception, the value "abc" is no shown. The output is: // "Error: the argument for option 'test' is invalid" throw po::validation_error(po::validation_error::invalid_option_value, "--test", "abc"); } catch(std::exception& e) { cerr << "Error: " << e.what() << "\n"; return -1; } catch(...) { cerr << "Unknown error!" << "\n"; return -1; } return 0; } // Compiled with g++ -std=c++11 -ggdb boost_program_options.cpp -o test -L/opt/local/lib -lboost_program_options-mt