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 21:54:54 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!cyclone.bc.net!news-in.mts.net!nf1.bellglobal.com!nf2.bellglobal.com!news20.bellglobal.com.POSTED!not-for-mail Message-ID: <404178F0.67730051@sympatico.ca> From: David Marceau X-Mailer: Mozilla 4.79 [en] (X11; U; Linux 2.4.17-10mdksmp i686) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Error-names. References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Sun, 29 Feb 2004 00:30:24 -0500 NNTP-Posting-Host: 65.92.164.241 X-Complaints-To: abuse@sympatico.ca X-Trace: news20.bellglobal.com 1078033642 65.92.164.241 (Sun, 29 Feb 2004 00:47:22 EST) NNTP-Posting-Date: Sun, 29 Feb 2004 00:47:22 EST Organization: Bell Sympatico Xref: archiver1.google.com comp.lang.ada:5941 Date: 2004-02-29T00:30:24-05:00 List-Id: Martin Klaiber wrote: > > Hi, > > this is not really a programming-problem (I hope), more a question > about english terms. > > I write a library with an interface to C. The Ada-exceptions shall > be turned into return-values for the C-functions. Like this: > > with Interfaces.C; > > package Something is > > -- Types: > type C_Integer is new Interfaces.C.int; > > -- Exceptions and errors: > General_Error : C_Integer := -1; > > Routine_Not_Defined : exception; > Routine_Not_Defined_Error : C_Integer := -2; > > and so on... > > package body Something is > > function Do_Something return C_Integer is > begin > ... > return 0; > exception > when Routine_Not_Defined => return Routine_Not_Defined_Error; > when others => return General_Error; > end Do_Something; > > end Something; > > My problem now is that I also want to define return values for > exceptions like Constraint_Error. But I can't define something like: > > Constraint_Error : C_Integer := -3; > > as Constraint_Error is the name for the exception. And I don't want to > use long names like: 'Routine_Not_Defined_Error_Constant' or similar. > I also don't want to rename the exceptions, as other Ada-Programs might > rely on them. > > Is there an english word instead of 'error' I could use? Like 'fault' > for instance or 'mistake'? > > Constraint_Fault, Constraint_Mistake. Hm, sounds strange to me. Would > it be alright though? > > Thanks a lot, > Martin I believe this is a case of C mentality/lifestyle being brought to Ada code. In my opinion this is bad Ada mentality/lifestyle The Ada idea from my understanding is to make it robust by separating all the different kinds of errors and dealing with each appropriate based on its context. The C style confuses and leaves you to wonder what the hell happened and what exactly was the root of the cause. The other thing about it is that because each case isn't handled separately the cleanup that one is supposed to handle for every different exception is not handled. SUGGESTION ----------- don't use when others all the time. make sure when others is used it is logged somewhere. don't return integers in exception handlers. it's ok to raise another more specific exception to a higher level. The special case ---------------- If you are writing a bridge that is controlled by C executable accessing an ada shared library then yes there may be a real reason to return constants for errors. Feel free to add other special cases if you want but I'm pretty sure this is the right direction to go instead of just porting a C mentality.