|
Boost : |
From: Eric Woodruff (Eric.Woodruff_at_[hidden])
Date: 2002-08-16 11:27:32
Ok,
I misread that you were changing the user's throw. In fact we have an
opportunity to do that already because boost::throw_exception needs to
replace all instances of throw. I don't know how this is supposed to happen
inside the rest of the STL, but if it did, everything would be happy.
----- Original Message -----
From: Peter Dimov
Newsgroups: gmane.comp.lib.boost.devel
Sent: Friday, 2002:August:16 9:42 AM
Subject: Re: shared_ptr inheritance relationship
From: "Eric Woodruff" <Eric.Woodruff_at_[hidden]>
> I'd like to have the inhertance relationship added to shared_ptr. Attached
> is a version of shared_ptr.hpp with the simple modification made.
Eric,
there is no inheritance relationship between pointers. Neither should there
be for shared_ptr's.
When Derived inherits from (IS-A) Base, there is a standard conversion from
Derived* to Base*, but Derived* does not inherit from (IS-NOT-A) Base*. If
it did, there would be a conversion from Derived** to Base**, and there
isn't.
The "throw by pointer" paradigm is obsolete. Its main usefulness was that
the exception object, typically allocated via "new", was guaranteed to be
immune from stack unwinding, and therefore, it was possible to use a
TRY/CATCH macro/longjmp replacement on compilers that didn't implement the
real thing.
Real exception handling doesn't need this idiom.
Here is a library solution to the problem that requires no paradigm changes,
and is less intrusive:
struct transportable_exception
{
virtual transportable_exception* clone() const = 0;
virtual void throw_this() const = 0;
};
template<class E> struct wrapped_exception: public E, public
transportable_exception
{
transportable_exception(E const & e): E(e) {}
virtual transportable_exception* clone() const
{
return new wrapped_exception(*this);
}
virtual void throw_this() const
{
throw *this;
}
};
template<class E> wrapped_exception<E> make_transportable_exception(E const
& e)
{
return wrapped_exception<E>(e);
}
// Old user code
throw std::logic_error();
// ...
catch(std::exception const & e)
// New user code
throw make_transportable_exception(std::logic_error());
// ...
// catch clauses unchanged
_______________________________________________
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