|
Boost : |
Subject: Re: [boost] program options (consider using BOOST_THROW_EXCEPTION)
From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2012-06-22 03:33:32
On Thu, Jun 21, 2012 at 11:44 PM, Vladimir Prus <ghost_at_[hidden]> wrote:
> On 20.06.2012 07:44, Rowan James wrote:
>
>> 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?
>>
>
> Sorry, but I kinda miss context here (and I did read your original post).
> What are advantages of
> using BOOST_THROW_EXCEPTION and what are drawbacks? Could you summarize
> those for me?
>
Allow me :-
BOOST_THROW_EXCEPTION, being a macro, is able to record the file name, the
function name, and the line number of the throw, which is useful when
diagnosing unexpected exceptions:
catch(...)
{
std::cerr << "Unexpected exception caught. Diagnostic information
follows.\n";
std::cerr << boost::current_exception_diagnostic_information();
}
The exception object is examined dynamically for any and all useful
information: type, what(), throw location, any stored boost::error_info
objects, etc. The location of the throw (if available) is formatted in a
way Visual Studio understands: double-clicking shows the throw location,
similarly to double-clicking compile errors.
The downside is that when templates are involved, BOOST_CURRENT_FUNCTION
(invoked by BOOST_THROW_EXCEPTION) can bloat the code. There is a Trac
ticket for this.
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