comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <stephen_leake@stephe-leake.org>
Subject: Re: Allocators and exceptions
Date: Thu, 13 Sep 2007 07:51:05 -0400
Date: 2007-09-13T07:51:05-04:00	[thread overview]
Message-ID: <ufy1idbrq.fsf@stephe-leake.org> (raw)
In-Reply-To: 1189601170.835400.72630@w3g2000hsg.googlegroups.com

Maciej Sobczak <see.my.homepage@gmail.com> writes:

> On 12 Wrz, 14:29, Stephen Leake <stephen_le...@stephe-leake.org>
> wrote:
>
>> The rule should be:
>>
>>     Constructors should not propagate exceptions up; they must handle
>>     all exceptions internally.
>
> No.
> What should the constructor do *after* handling the exception?
> Leave the object half-baked?
> Do you want to introduce additional states to the object design just
> to handle the "oops I'm not initialized" case?
>
> The only reasonable solution is probably to use custom factories
> instead of built-in allocators.
>
> But... can we prohibit the user from using the allocator for the given
> type?

Hmm. You seem to be equating "allocator" with "constructor"; I was
not.

I thought you meant "custom factory" when you said "constructor".

Hmm. Maybe you mean only Finalization.Initialize by "constructor";
that is called by "new".

In any case, I'll modify my statement;

    Constructors (ie Initialize or user-built factory functions) must
    handle all exceptions internally. If in some situation the object
    cannot be properly constructed, any memory allocated should be
    deallocated, all other appropriate cleanups done, and then a final
    "Failed" exception should be raised to indicate the failure to the
    caller.

The point is that the caller of the constructor either gets a properly
initialized object, or a single well-defined exception indicating that
the object could not be created. In the latter case, all proper
cleanup is already done by the time the final exception is raised.

I think that is consistent with what you want to have happen.

If the constructor is designed to return an access value, an
alternative to raising the final exception is to return null, but an
exception is probably better.

-- 
-- Stephe



  parent reply	other threads:[~2007-09-13 11:51 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-09  7:40 Allocators and exceptions Maciej Sobczak
2007-09-09 12:17 ` anon
2007-09-09 20:31   ` Maciej Sobczak
2007-09-09 22:43     ` Simon Wright
2007-09-10 12:10       ` Maciej Sobczak
2007-09-10 19:08         ` Simon Wright
2007-09-10  2:56     ` anon
2007-09-10 12:42     ` Dmitry A. Kazakov
2007-09-10 21:48       ` Maciej Sobczak
2007-09-11  9:16         ` Dmitry A. Kazakov
2007-09-11  9:19           ` Maciej Sobczak
2007-09-11 12:27             ` Dmitry A. Kazakov
2007-09-11 19:07               ` Maciej Sobczak
2007-09-11 22:56                 ` Georg Bauhaus
2007-09-12 12:36                   ` Maciej Sobczak
2007-09-12 22:19                     ` Randy Brukardt
2007-09-12  9:32                 ` Dmitry A. Kazakov
2007-09-12 12:42                   ` Maciej Sobczak
2007-09-12 15:25                     ` Dmitry A. Kazakov
2007-09-12 12:29             ` Stephen Leake
2007-09-12 12:46               ` Maciej Sobczak
2007-09-12 20:53                 ` Simon Wright
2007-09-12 22:32                   ` Randy Brukardt
2007-09-12 23:43                     ` Simon Wright
2007-09-13  3:42                       ` Randy Brukardt
2007-09-13  3:36                     ` Randy Brukardt
2007-09-13  9:43                     ` Maciej Sobczak
2007-09-12 22:25                 ` Randy Brukardt
2007-09-13 11:51                 ` Stephen Leake [this message]
2007-09-12 14:14               ` Markus E L
2007-09-10 10:37 ` Allocators and exceptions => Read Me First anon
2007-09-10 12:16   ` Maciej Sobczak
2007-09-10 22:10     ` Allocators and exceptions => Trying Again anon
2007-09-10 23:15       ` Markus E L
2007-09-10 15:44 ` Allocators and exceptions Adam Beneschan
2007-09-10 21:58   ` Maciej Sobczak
2007-09-10 22:07   ` Jeffrey R. Carter
2007-09-11  9:14   ` Dmitry A. Kazakov
2007-09-11  9:23     ` Maciej Sobczak
2007-09-11  2:36 ` Randy Brukardt
2007-09-11 15:33   ` Adam Beneschan
2007-09-11 19:21     ` Maciej Sobczak
2007-09-11 21:56     ` Adam Beneschan
2007-09-12  0:34       ` Jeffrey R. Carter
2007-09-12 12:13         ` Maciej Sobczak
2007-09-12 16:34           ` Jeffrey R. Carter
2007-09-12 23:50             ` Jeffrey R. Carter
2007-09-12 12:22       ` Maciej Sobczak
2007-09-12 14:11         ` Markus E L
2007-09-12 16:08         ` Adam Beneschan
2007-09-12 20:35           ` Dmitry A. Kazakov
2007-09-12 21:01             ` Adam Beneschan
2007-09-12 22:45             ` Randy Brukardt
2007-09-13  7:48               ` Dmitry A. Kazakov
2007-09-12  3:08 ` Allocators and exceptions -- Debugging says memory leak! anon
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox