|
Boost Users : |
From: Robert Ramey (ramey_at_[hidden])
Date: 2007-03-01 22:04:03
There are differing opinions on this. For example:
http://www.arkestra.demon.co.uk/errors_cpp.html#acquire_resources_in_constructors
and
http://www.research.att.com/~bs/bs_faq2.html#ctor-exceptions
Robert Ramey
Andrew Mellinger wrote:
> On 3/1/07 2:18 PM, "gast128" <gast128_at_[hidden]> wrote:
>
>> Dear all,
>>
>> I ran into an exception thrown by the constructor. But there is no
>> way to call 'delete_created_pointers' on the object since the object
>> is never fully created (see below)
>>
>> Is there something to do about?
>
> <snip>
>
>
>> This throwing c++ constructor stuff is btw the way to transport
>> errors according to a lot of c++ gurus. But my persnonal opinion is
>> that it sucks. Every created object must be guarded with exception
>> safety. For large applications, this exception mecahnism is very
>> tricky and sources for a lot unwanted application terminations or
>> memory leaks.
>
> I agree. At my workplace we have a convention. For heavyweight
> objects that would do interesting things in their constructors we
> instead use the alloc-init paradigm of Objective-C. In this model,
> the constructor does simply non-error things, then a corresponding
> init (or even suite of init methods) does the interesting things.
> This has the added benefit that the init method can be overridden in
> subclasses, and you don't need to re-implement all the behaviors.
>
> -Andrew
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net