|
Boost : |
From: johan_ericsson_at_[hidden]
Date: 2002-11-20 18:46:47
-----Original Message-----
From: David Abrahams [mailto:dave_at_[hidden]]
Sent: Wednesday, November 20, 2002 1:40 PM
To: Boost mailing list
Subject: Re: [boost] Do we need a boost_exception class or idiom?
>"Fernando Cacciola" <fernando_cacciola_at_[hidden]> writes:
>> I'm not sure if a boost exception class is *needed*, but I see no problem in
>> having one.
>> Anyway, IIF such an exception class is defined, I *strongly* encourage (as I
>> did in the past) that it provides:
>>
>> virtual void raise() const
>> {
>> #ifndef BOOST_NO_EXCEPTIONS
>> throw *this ;
>> #endif
>> }
>>
>> and that boost libraries throw such exceptions *only* by calling .raise():
>> i.e. never with a throw expression directly in the user code.
>1. Why should this be a virtual function? The dynamic type of an
> exception object is never used in a throw expression.
I can think of one reason; if you are going to add a clone() method call to
the exception hierarchy. Then you could save a copy of the exception object
and rethrow it using the virtual method call. This is useful when you want to
pass an exception across threads. It's also useful if you are wrapping a C
interface that includes callbacks.
Johan
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk