Boost logo

Boost Users :

From: Vladimir Prus (ghost_at_[hidden])
Date: 2006-05-10 02:31:07

Roel wrote:

> Hi,
> I've been using boost::program_options but I have some questions about it.
> First: to catch errors that the users makes when specifying command-line
> options (eg I declared an option to be integer-only but the user
> specified a string), I surrounded the call to store() by a try/catch
> block:
> try {
> boost::program_options::store(
> boost::program_options::command_line_parser(argc, argv).
> options(desc).positional(p).run(), vm);
> }
> catch (boost::program_options::invalid_option_value e) {
> }
> But now how do I give a meaningfull error message? The what() function
> of invalid_option_value is private, what other options do I have?

You can use top-level try-block in main that catches std::exception. That
will catch all possible errors, and not just specific

However, non-accessible 'what' is still a bug. I've fixed this, and will
commit as soon as Sourceforce's CVS is operational agian.

> Secondly, is there a mechanism to check the relation between options? I
> have a number of options: -a, -m and -d for add, modify and delete
> respectively; I want only one of them to be allowed at the same time.
> Also, when the -a option is specified, the -t and -r options are valid,
> and only then. Do I have to check all of that manually? Thanks.

I'm afraid this is not supported at the moment.

- Volodya

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at