From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,6b1a1ed8b075945 X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Newsgroups: comp.lang.ada Subject: Re: Allocators and exceptions References: <1189323618.588340.87180@o80g2000hse.googlegroups.com> <1189369871.672082.162750@50g2000hsm.googlegroups.com> <1189460936.295604.143720@r29g2000hsg.googlegroups.com> <1189502377.626510.172690@22g2000hsm.googlegroups.com> From: Markus E L Date: Wed, 12 Sep 2007 16:14:23 +0200 Message-ID: User-Agent: Some cool user agent (SCUG) Cancel-Lock: sha1:l7308uulW0Her+9ksVEfgGvCgEQ= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii NNTP-Posting-Host: 88.74.57.86 X-Trace: news.arcor-ip.de 1189606188 88.74.57.86 (12 Sep 2007 16:09:48 +0200) X-Complaints-To: abuse@arcor-ip.de Path: g2news2.google.com!news3.google.com!feeder3.cambrium.nl!feed.tweaknews.nl!newsfeed.kamp.net!newsfeed.kamp.net!news.unit0.net!newsfeed.arcor-ip.de!news.arcor-ip.de!not-for-mail Xref: g2news2.google.com comp.lang.ada:1920 Date: 2007-09-12T16:14:23+02:00 List-Id: Stephen Leake wrote: > Maciej Sobczak writes: > >> On 11 Wrz, 11:16, "Dmitry A. Kazakov" >> wrote: >> >>> >>> P.S. Exceptions in constructors is a bad idea. >>> >>> > No, it's a very good idea. Otherwise you have to deal with half-baked >>> > objects, which is Even Bigger Mess (tm). >>> >>> This is what you get when the exception is propagated out of a constructor. >> >> In this case I want the constructor to be rolled back. >> Without exceptions (and rollback) the only option for handling errors >> in initialization of (sub)components is to leave them half-baked. > > The point is that the constructor itself must do the roll-back, and > leave the object in a consistent state. > > The rule should be: > > Constructors should not propagate exceptions up; they must handle > all exceptions internally. Forgive me that I contradict. The power of exceptions in a properly designed language is, that it allows to handle problems during complex object constructions, like T = new (something(new something_else ...) and recover fully. Else we're back to testing failure after every step again and manuall, as it was/is in C. Maybe I misunderstood the problem altogether, though. Regards --- Markus