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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,699cc914522aa7c4 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news2.google.com!news.germany.com!newsfeed.freenet.de!border2.nntp.ams.giganews.com!nntp.giganews.com!newsfeed101.telia.com!nf02.dk.telia.net!news.tele.dk!news.tele.dk!small.news.tele.dk!lnewsinpeer00.lnd.ops.eu.uu.net!bnewsinpeer00.bru.ops.eu.uu.net!emea.uu.net!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail Newsgroups: comp.lang.ada Subject: Re: Structured exception information From: Georg Bauhaus In-Reply-To: References: Content-Type: text/plain Content-Transfer-Encoding: 7bit Organization: # Message-ID: <1168885771.30643.20.camel@localhost> Mime-Version: 1.0 X-Mailer: Evolution 2.6.1 Date: Mon, 15 Jan 2007 19:29:31 +0100 NNTP-Posting-Date: 15 Jan 2007 19:27:32 CET NNTP-Posting-Host: 7ecdf8b6.newsspool4.arcor-online.net X-Trace: DXC=AdMFXF[^Ce0RadXUBHgFh34IUKN[W On Mon, 2007-01-15 at 12:28 -0500, Robert A Duff wrote: > Maciej Sobczak writes: > > > If there are problems during the execution of the constructor function, > > the exception is raised, so that there is no X object in a bad state. > > How can I pass some error information from the constructor function out, > > so that it's used when the exception is handled? > > There is no good way to do this in Ada. You can attach any information > you like to an exception, if you are willing to encode it as a String -- > but then you lose static type checking. You can put the info in a > global variable, but that's bad for several reasons (not task safe, > can be accessed outside of any handler, ...). You can put the info in a > Task_Attribute, but that's rather a pain -- verbose and inefficient. I'm still wondering whether or not an Ada compiler could provide a special kind of closure for this case? We do already get stack traces. (I don't know compilers so this is just a guess...) package Handling is -- -- info to be attached to an exception occurence -- type State is tagged record info: Integer; end record; end Handling; with Handling; use Handling; procedure foo is x: Integer; function Env return State'class is begin return State'(info => x); end Env; begin if 1 > 1 then raise Constraint_Error with Env'access; end if; end foo;