Boost logo

Boost :

From: Llew Sion Goodstadt (leo.goodstadt_at_[hidden])
Date: 2004-09-15 09:47:30


Dear Volodya,

The version of Boost.program_options I am using throws lots of informative
exceptions to indicate precisely what has gone wrong.

The exception is where an incorrect argument to an option has been supplied

e.g.
    --some_arg "abc"
where
    --some_arg 0.6
is expected.

The error message is annoyingly non-descript and it can be difficult to
figure out which particular optional argument has been mis-specified.

This imprecision is because when program_options::validation_error is being
thrown, it is not clear which option is being parsed.

Could I suggest that this particular exception is caught in:
void store(const parsed_options& options, variables_map& xm,
              bool utf8)
and the option context added back in (and the same exception type
re-thrown):

void store(const parsed_options& options, variables_map& xm, bool utf8)
{

...

  // First, convert/store all given options
  for ( size_t i = 0; i < options.options.size(); ++i )
  {
    const string& name = options.options[i].string_key;
    try
    {

...

    }
    catch ( validation_error& e )
    {
      throw validation_error("[--" + name + "]: " + e.what());
    }

  }

...
}

What do you think?

Leo Goodstadt
MRC Functional Genetics Unit
University of Oxford


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