comp.lang.ada
 help / color / mirror / Atom feed
From: David Marceau <davidmarceau@sympatico.ca>
Subject: Re: Error-names.
Date: Sun, 29 Feb 2004 00:30:24 -0500
Date: 2004-02-29T00:30:24-05:00	[thread overview]
Message-ID: <404178F0.67730051@sympatico.ca> (raw)
In-Reply-To: qrf6h1-mt1.ln1@martinkl.dialup.fu-berlin.de

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.



  parent reply	other threads:[~2004-02-29  5:30 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-02-28 12:58 Error-names Martin Klaiber
2004-02-28 13:35 ` Error-names Martin Dowie
2004-02-28 15:26   ` Error-names Martin Klaiber
2004-02-28 17:19     ` Error-names Marius Amado Alves
2004-02-28 18:31       ` Error-names Martin Klaiber
2004-02-28 19:47         ` Error-names tmoran
2004-02-28 20:29           ` Error-names Martin Klaiber
2004-02-29 19:03           ` Error-names Jeffrey Carter
2004-02-29 20:04             ` Error-names tmoran
2004-02-29 23:24               ` Error-names Björn Persson
2004-03-01 11:29                 ` Error-names Martin Klaiber
2004-03-01 12:48                   ` Error-names Marius Amado Alves
2004-03-02  2:15                     ` Error-names Jeffrey Carter
2004-02-29 20:33             ` Error-names Martin Klaiber
2004-02-29 23:43               ` Error-names tmoran
2004-03-01 11:20                 ` Error-names Martin Klaiber
2004-03-07 15:10                   ` Error-names Björn Persson
2004-03-08  5:42                   ` Error-names Dave Thompson
2004-02-28 20:26         ` Error-names Jacob Sparre Andersen
2004-02-28 18:29 ` Error-names Alexandre E. Kopilovitch
2004-02-29  5:30 ` David Marceau [this message]
2004-02-29 12:17   ` Error-names Martin Klaiber
2004-02-29 19:56     ` Error-names David Marceau
2004-02-29 21:57       ` Error-names Martin Klaiber
2004-03-01 23:20       ` Error-names Randy Brukardt
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox