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,699cc914522aa7c4 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!v45g2000cwv.googlegroups.com!not-for-mail From: "Adam Beneschan" Newsgroups: comp.lang.ada Subject: Re: Structured exception information Date: 15 Jan 2007 14:42:42 -0800 Organization: http://groups.google.com Message-ID: <1168900961.743193.85000@v45g2000cwv.googlegroups.com> References: NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" X-Trace: posting.google.com 1168900971 5385 127.0.0.1 (15 Jan 2007 22:42:51 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 15 Jan 2007 22:42:51 +0000 (UTC) User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.7.12-1.3.1,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: v45g2000cwv.googlegroups.com; posting-host=66.126.103.122; posting-account=cw1zeQwAAABOY2vF_g6V_9cdsyY_wV9w Xref: g2news2.google.com comp.lang.ada:8146 Date: 2007-01-15T14:42:42-08:00 List-Id: Maciej Sobczak wrote: > Hi, > > Consider an object created by a constructor function: > > X : My_Type := My_Constructor(Some_Parameters); > > My_Type is Controlled_Limited to ensure control over initialization and > finalization. The idea of constructor function is to prevent the > existence of objects that are not yet initialized, half-baked, in a bad > state, etc. If the object exists, it's ready for use. > > 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? > Obviously, some message can be attached to the exception occurence, but > it doesn't scale well - I might want to pass some more data, possibly > structured (some error code, some reason code, some timestamp, some > whatever else, ...). > > Yes, I'm asking for "throwing objects", in the C++ parlance. > > How to do this in Ada? > If I cannot - how to solve this design problem? Hmmm ... I almost thought this could be done by writing your own package that provides its own Raise routine, something like type Extra_Info is ... procedure My_Own_Raise (E : in Ada.Exceptions.Exception_ID; Info : Extra_Info; Message : in String := ""); The implementation of this routine would call Ada.Exceptions.Raise_Exception(E,Message), and at the same time attach "Info" to the exception occurrence, so that another routine in this package could retrieve the information from the exception occurrence. (Is this the sort of design you had in mind?) Unfortunately, you don't know what the Exception_Occurrence is before you call Raise_Exception. Maybe if you implemented it something like this: procedure My_Own_Raise (E : in Ada.Exceptions.Exception_ID; Info : Extra_Info; Message : in String := "") is begin Ada.Exceptions.Raise_Exception (E, Message); exception when Occ : Others => ... do something that associates Occ with Info, that another ... subprogram in the package could then retrieve Ada.Exceptions.Reraise_Occurrence (Occ); end My_Own_Raise; But since Exception_Occurrence is a limited private type that doesn't have its own "handle" (there's no Exception_Occurrence_Id in Ada.Exceptions), I still don't see how this could be done. Anyone else have any ideas? Or did I totally misunderstand the problem? -- Adam