|
Boost : |
Subject: Re: [boost] Boost and exceptions
From: Robert Ramey (ramey_at_[hidden])
Date: 2012-06-23 19:19:46
Emil Dotchevski wrote:
> On Sat, Jun 23, 2012 at 12:11 PM, Robert Ramey <ramey_at_[hidden]> wrote:
> For example, if Boost Serialization calls boost::throw_exception, an
> application that serializes data that comes from a web site could
> store the web address, the user name, port number, or whatever else
> the application needs to handle the exception.
the serialization libary will likely not have this information. Geneally
the serilalizaiton library uses some sort of stream i/o object. Many
times errors are detected in the stream. At this point, the none
of the library knows what the file name is so it can't be added
in until some way higher level. The current archive_exception
class holds all the useful information which is available.
>> your code when you eventually can eventually rethrow
>>
>> catch (std::exception e){
>> BOOST_EXCEPTION_THROW_EXCEPTION(e)
>> }
>>
>
> Second, even if you catch std::exception & obj, throwing obj will
> slice, erasing the dynamic type of the original exception.
It's hard to see the slicing through the macro
isn't the standard way of handling this better?
catch(std::exception & e){
std::exception_ptr e = std::current_exception();
std::rethrow_exception(e);
}
or if you want to add your own sauce
catch(std::exception &e){
std::exception_ptr e = std::current_exception();
someclass se(e, extra stuff); // home brew or from some library
std::throw(se);
}
or if you want to catch anyone's stuff
catch(...){
std::exception_ptr e = std::current_exception();
my_unknown_exception me(e); // though its not clear what the upper level
could do with this
}
this would confine the usage of boost exception to areas where the user
can decide whether or not he want's to use it. It looks to me that the
standard
was conceived to support just this usage. It doesn't require anything
special at the
throw point. The standard facility of using one's own exception class is
sufficient.
> If the point of this catch is to translate the type of the exception
> object, it has to look like:
>
> catch( foo & e )
> {
> BOOST_THROW_EXCEPTION(my_foo(e));
> }
> catch( bar & e )
> {
> BOOST_THROW_EXCEPTION(my_bar(e));
> }
> catch( foobar & e )
> {
> BOOST_THROW_EXCEPTION(my_foobar(e));
> }
> catch( ... )
> {
> assert(0);
> }
>
> And of course this nonsense has to go around every call to Boost
> Serialization.
>
> WHY?
lol - well you've got a point here. But I not convinced a huge problem in
practice.
I would expect most of these would be placed at the much higer levels.
>> How is this different from using std::exception ?
> You can't add your own stuff to a live std::exception.
I believe equivalent functionality is available. I believe that boost
exception
is more intrusive that it has to be.
Robert Ramey
> Emil Dotchevski
> Reverge Studios, Inc.
> http://www.revergestudios.com/reblog/index.php?n=ReCode
>
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk