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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no 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!news4.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsfeed.hanau.net!news-fra1.dfn.de!newsfeed.ision.net!newsfeed2.easynews.net!ision!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Structured exception information Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <1168885771.30643.20.camel@localhost> Date: Mon, 15 Jan 2007 20:44:53 +0100 Message-ID: NNTP-Posting-Date: 15 Jan 2007 20:44:50 CET NNTP-Posting-Host: ebab1995.newsspool4.arcor-online.net X-Trace: DXC=^M>0H^=b6oS=>bdbdS?M0Y4IUK:X1^][m;GX X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:8141 Date: 2007-01-15T20:44:50+01:00 List-Id: On Mon, 15 Jan 2007 19:29:31 +0100, Georg Bauhaus wrote: > 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? When closures should be supported then they should not be any special... > 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; Ada 2005 will allow non-library-level extensions. So? What if Env were declared within Foo? Exceptions are usually considered as non-local jumps. But there is also another mental model possible. One could consider them as a kind of rendezvous with the handler. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de