Boost logo

Boost :

Subject: Re: [boost] program options (consider using BOOST_THROW_EXCEPTION)
From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2012-06-19 15:55:08


On Tue, Jun 19, 2012 at 6:12 AM, Roger Martin <roger_at_[hidden]>wrote:

> Hi boost,
>
> At version 1.49.0
>
> In testing command line with known unknowns such as -V a location unknown
> exception is thrown from inside program_options recommending to use
> BOOST_THROW_EXCEPTION. I've been trying to find this and apply
> BOOST_THROW_EXCEPTION to eliminate the verbosity for users:
> ----
> 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.

Just catch boost::program_options::unknown_option and display a
user-friendly message:

catch( boost::program_options::unknown_option & e )
{
  std::cerr << "Unknown option!";
}
catch( ... )
{
  std::cerr <<
    "Unrecognized exception, diagnostic information follows\n" <<
    boost::current_exception_diagnostic_information();
}

Emil Dotchevski
Reverge Studios, Inc.
http://www.revergestudios.com/reblog/index.php?n=ReCode


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