Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2004-03-27 19:23:50


"Klaus Nowikow" <nowikow_at_[hidden]> writes:

> Reece Dunn wrote:
> [snip]
>> A trick I use when handling HRESULT error codes is to have a
>> class like this
>> (adapted for int error type):
>>
>> class errorcheck
>> {
> [snip]
>> public:
>> inline errorcheck( int ec ): error( ec )
>> {
>> if( ec < 0 ) throw( *this );
>> }
>
> Careful. Throwing an exception from a constructor
> means that the object won't be constructed (i. e., does not exist).
> So you are throwing a non-existing object here.
>
> Or am I wrong?

You're wrong. *this is copied before it is thrown. Still, the idiom
above seems a bit suspicious, unless you somehow prevent derivation
from errorcheck.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk