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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,bc745b8412f53f25 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2004-02-28 12:26:23 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!news2.telebyte.nl!news.jgaa.com!news.hacking.dk!pnx.dk!munin.nbi.dk!not-for-mail From: Jacob Sparre Andersen Newsgroups: comp.lang.ada Subject: Re: Error-names. Date: 28 Feb 2004 21:26:20 +0100 Organization: Munin Sender: sparre@sparre.crs4.it Message-ID: References: NNTP-Posting-Host: 80.241.165.51 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: munin.grove.home 1077999981 19376 80.241.165.51 (28 Feb 2004 20:26:21 GMT) X-Complaints-To: sparre@munin.nbi.dk NNTP-Posting-Date: Sat, 28 Feb 2004 20:26:21 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: archiver1.google.com comp.lang.ada:5937 Date: 2004-02-28T21:26:20+01:00 List-Id: Martin Klaiber wrote: > Marius Amado Alves wrote: > > function Main return Error_Code_Type is > > -- exception-raising calls here > > exception > > when E : others => return Error_Code_Of (E); > > end; > > > Now you only have to implement Error_Code_Of. > > > (Ain't top-down design great? ;-) > > > The 'trick' you could be missing is the "E : others" construct > > above. E is the exception occurence. From it you can go to the > > exception name. See package Ada.Exceptions--or, better yet, > > section 11.4 of the ARM. > > Well, if I understand it right, I still have to distinguish between > the different exceptions before I call Error_Code_Of, is this right? No. E is like a renaming of whatever exception actually was raised. > Like this (assume I have 5 exceptions A to E): > > function Main return Error_Code_Type is > -- exception-raising calls here > exception > when A : others => return Error_Code_Of (A); > when B : others => return Error_Code_Of (B); > when C : others => return Error_Code_Of (C); > when D : others => return Error_Code_Of (D); > when E : others => return Error_Code_Of (E); > end; No, that wouldn't work. Just: [...] exception when Raised_Exception : others => return Error_Code_Of (Raised_Exception); end; If the exception raised is A, then Ada.Exceptions.Exception_Name (Raised_Exception) will return the string "A" (or however it is that the compiler names the exception you call A. Read the suggested part of the reference manual. Jacob -- "We will be restoring normality as soon as we are sure what is normal anyway."