Boost logo

Boost :

Subject: Re: [boost] program options (consider using BOOST_THROW_EXCEPTION)
From: Rowan James (rowanj_at_[hidden])
Date: 2012-06-19 23:44:53


On 20 June 2012 05:55, Emil Dotchevski <emildotchevski_at_[hidden]> wrote:

> On Tue, Jun 19, 2012 at 6:12 AM, Roger Martin <roger_at_[hidden]
> >wrote:
>
> > Command line incorrect: Throw location unknown (consider using
> > BOOST_THROW_EXCEPTION)
> > Dynamic exception type: boost::exception_detail::**
> > clone_impl<boost::exception_**detail::error_info_injector<**
> > boost::program_options::**unknown_option> >
> > std::exception::what: unknown option -V
> >
>
> The output you're seeing is generated by boost::diagnostic_information,
> and that's not a user-friendly but rather a diagnostic message. The
> suggestion to use BOOST_THROW_EXCEPTION refers to the "Throw location
> unknown". If BOOST_THROW_EXCEPTION was used by the library, the diagnostic
> message would have been more complete and include the file/line of the
> throw.
>
>
Or, to use the plain information in the exception; ignore the diagnostic
information and just use the what() member of the exception:

try
{
    // ...
}
catch (std::exception& ex)
{
    std::cout << ex.what() << std::endl;
}

Note that the boost::diagnostic_information() is showing what the result of
that is for the exception in the last line: "unknown option -V"

Also, be aware that this is not an especially friendly way of doing this;
the exception string is never going to be translated for the current
locale, is prone to change without notice, etc. etc. Roger is suggesting
the Right Way.

On a related note; is there interest in a patch set to use
BOOST_THROW_EXCEPTION to add this (yes, programmer-oriented) information to
the exceptions thrown by Program Options and/or other Boost libraries?

I'd understand if there is some reason to not using it that I've missed;
like minimising dependencies, or no-exception support, for example.
 However, I use Boost.Exception ( and boost::diagnostic_information() )
extensively, and I often encounter instances where exceptions thrown by
Boost libraries themselves lack the information that would be added;
Boost.Filesystem and Boost.Format come to mind specifically.


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