From: Vladimir Prus (ghost_at_[hidden])
Date: 2004-09-15 10:19:01
> 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
> --some_arg "abc"
> --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.
I agree with you.
> 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
> catch ( validation_error& e )
> throw validation_error("[--" + name + "]: " + e.what());
> What do you think?
Personally, I would prefer something like:
However, that would require to format the string inside the 'what' method,
const char* what() const
m_error_message = logic_error::what();
m_error_message = "--" + m_option_name + " : " + m_error_message;
I've used this approach once, but I'm not sure if has any hidden problems.
I'd appreciate if some exception handling expert could comment on this.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk