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-29 12:35:19 PST Path: archiver1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!martinkl.dialup.fu-berlin.DE!not-for-mail From: Martin Klaiber Newsgroups: comp.lang.ada Subject: Re: Error-names. Date: Sun, 29 Feb 2004 21:33:35 +0100 Organization: Freie Universitaet Berlin Sender: Martin Klaiber Message-ID: References: <2Iq0c.15247$aT1.13123@newsread1.news.pas.earthlink.net> NNTP-Posting-Host: martinkl.dialup.fu-berlin.de (130.133.237.205) X-Trace: news.uni-berlin.de 1078086917 56775910 F 130.133.237.205 (10182) X-Orig-Path: not-for-mail User-Agent: tin/1.5.12-20020427 ("Sugar") (UNIX) (Linux/2.4.24 (i586)) Xref: archiver1.google.com comp.lang.ada:5957 Date: 2004-02-29T21:33:35+01:00 List-Id: Jeffrey Carter wrote: > tmoran@acm.org wrote: >> subtype Exception_Codes is Interfaces.C.Int range -10 .. 1; >> Coded_Exception_List : constant array(Exception_Codes) >> := (Constraint_Error'Identity, >> Program_Error'Identity, >> Storage_Error'Identity, >> Tasking_Error'Identity, >> Ada.IO_Exceptions.Status_Error'Identity, >> Ada.IO_Exceptions.Mode_Error'Identity, >> Ada.IO_Exceptions.Name_Error'Identity, >> ... >> function Error_Code_Of(E : Ada.Exceptions.Exception_Occurrence) >> return Exception_Codes is >> use Ada.Exceptions; >> begin >> for i in Coded_Exception_List'range loop >> if Exception_Identity(E) = Coded_Exception_List(i) then >> return i; >> end if; >> end loop; >> raise; -- we have no code for this exception! re-raise it >> end Error_Code_Of; > This is pretty much what I would have suggested if Moran hadn't beat me > to it. However, I think you can't use "raise" here without an exception > name, since we're not necessarily in an exception handler. You could use > Ada.Exceptions.Raise_Exception (E), but I suspect what is really wanted, > based on the OP's earlier messages, is to return General_Error_Code. Yes, General_Error_Code shall be a fallback in case there is no special handler for a certain exception. I implemented it like this: function Get_Error_Code (E : Exception_Occurrence) return C_Integer is begin if Exception_Identity (E) = Program_Error'Identity then return Program_Error_Code; elsif Exception_Identity (E) = Constraint_Error'Identity then return Constraint_Error_Code; elsif ... ... else return General_Error_Code; end if; end Get_Error_Code; Not as elegant as Toms(?) code with the array but it works ok. It's a pity that I can't use "case" instead of "if". The compiler moans that Exception_Id is not a discrete type. Martin