Boost logo

Boost :

Subject: Re: [boost] [program_options] Improving error text in exceptions
From: Vladimir Prus (vladimir_at_[hidden])
Date: 2011-11-15 03:56:35


Leo Goodstadt wrote:

> As a long time fan of boost::program_options, I would very much like
> to make the error messages in program_options exceptions more
> consistent and informative.
...
> If this is useful, I shall painstaking go through the code and submit
> a patch.

Leo,

I've looked over the error messages you have proposed, and I think it's
an overall improvement. I would appreciate patch to make this change.

> Not sure what these mean and have left them alone.
>
> libs/program_options/src/parsers.cpp:112:
> boost::throw_exception(error("long name required for config
> file"));

When parsing config file, every option should have long name. That is,
short-only options, like ",h" don't work.

>
> libs/program_options/src/config_file.cpp:60:
> boost::throw_exception(error("bad prefixes"));

Config file allow options names like "foo*". The code in question
verifies there are no conflicting options. I.e. if you have two options
named "foo*" then it's not clear how to parse foo1 or foo2.
>
> libs/program_options/src/value_semantic.cpp:102:
> boost::throw_exception(multiple_values());

For untyped option, at most one token can be specified as the value.

> libs/program_options/src/convert.cpp:66:
> boost::throw_exception(std::logic_error("character conversion
> failed"));
>
> libs/program_options/src/convert.cpp:74:
> boost::throw_exception(std::logic_error("character conversion
> failed"));
>
> libs/program_options/src/value_semantic.cpp:33:
> boost::throw_exception(std::runtime_error("UTF-8 conversion not
> supported."));

Not really sure these can be reported to users -- we don't know
which option is being parsed. Maybe, more specific exceptions must
be used, which should be caught when we call 'convert' elsewhere,
and better-worded exception be thrown.

Thanks!

-- 
Vladimir Prus
CodeSourcery / Mentor Graphics
+7 (812) 677-68-40

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk