Boost logo

Boost :

Subject: Re: [boost] [exception]throw_exceptions concerns
From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2009-01-04 02:05:07


On Sat, Jan 3, 2009 at 5:43 PM, Gennadiy Rozental <rogeeff_at_[hidden]> wrote:
> Emil Dotchevski <emildotchevski <at> gmail.com> writes:
>> On Fri, Jan 2, 2009 at 5:19 AM, Gennadiy Rozental
> Can you please elaborate? If I use
>
> boost::throw_exception( my_exception() );
>
> How do I catch it?

Did you try catch(my_exception &)? :)

The other two options are:

- catch(boost::exception &) - this catches any exception emitted by
boost::throw_exception. Also, see
http://www.boost.org/doc/libs/1_37_0/libs/exception/doc/tutorial_transporting_data.html.

- catch(...) - you can use current_exception/exception_ptr in any
catch, see http://www.boost.org/doc/libs/1_37_0/libs/exception/doc/current_exception.html.

>> "Exposed to" is technically correct, but that exposure is limited to
>> "boost/exception/exception.hpp", which does not include any headers
>> and was carefully designed for the purpose of the throw_exception
>> integration.
>
> It adds <typeinfo>, which may be serious, since shared_ptr takes special care to
> work around the case when typeinfo is not supported by underlying system.

I'll repeat that "boost/exception/exception.hpp" does not #include anything.

Other Boost Exception headers do use <typeinfo>, but the library takes
the same special care as shared_ptr to work around the case when
typeinfo is not supported.

>> Boost::exception is copy constructable but its copy constructor is
>> protected to prevent the user from accidentally slicing the exception
>> object using a catch(boost::exception e) instead of the correct
>> catch(boost::exception & e).
>
> Fine. But both exceptions have to be disabled in a header (especially since it's
> now compiled pretty much always)

I read the above twice but I don't get what you're saying.

>> > a) Was it agreed that practically all Boost users are now exposed to the
>> > Boost.Exceptions library by default whether they are willing or not
>>
>> There was rather lack of interest in discussion before this change in
>> throw_exception was implemented, but there was a later discussion
>> which lead to refactoring of the throw_exception hook.
>
> Can you please point me?

Here's one thread but there were a couple more before and after it:
http://www.nabble.com/-exception--library-update-to19377623.html#a19406381

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