[program_options] Uncatchable Errors

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

[program_options] Uncatchable Errors

Merrill Cornish
I have a minimal program below that uses the program_options
library.  If executed with no options or with --help as an option,
it correctly prints "End of option processing" and does nothing else.

However, if you give it an unexpected option such as --x, then
(in my case) Zone Alert pops up saying that "somone" is trying
to launch Dr Watson.  If the try/catch is omitted, a message is
printed to the console: "This application has requested the Runtime
to terminate it in an unusual way.  Please contact the application's
support team for more information."

Am I doing something wrong to make unexpected options behave
so badly?


#include <iostream>
#include <stdexcept>
#include "boost/program_options.hpp"
namespace po = boost::program_options;
using namespace std;

int main(int argc, char* argv[]) {
    try {
        po::options_description general_verbose("Options");
                ("help,h", "    Display this help message.");

    po::variables_map vm;
        po::store(po::command_line_parser(argc, argv).
                      options(general_verbose).run(), vm);
    catch(std::exception ex) {
        cout << "Exception: " << ex.what() << endl;
    catch(...) {
        cout << "Unknown exception." << endl;
        cout << "End of option processing." << endl;

Boost-users mailing list
[hidden email]