comp.lang.ada
 help / color / mirror / Atom feed
From: "Yannick Duchêne (Hibou57)" <yannick_duchene@yahoo.fr>
Subject: Re: best practice: error handling
Date: Sat, 11 Jun 2011 15:31:39 +0200
Date: 2011-06-11T15:31:39+02:00	[thread overview]
Message-ID: <op.vwwyi11bule2fv@douda-yannick> (raw)
In-Reply-To: 0b95a2a1-6e3d-4ad1-a832-e3099a9bce37@v8g2000yqb.googlegroups.com

Le Tue, 31 May 2011 16:01:19 +0200, milouz <a.michelizza@gmail.com> a  
écrit:

> Hi,
>
> I'm wondering about the best way to handle errors in Ada when calling
> a function/procedure that may fails.
>
> For example, when programming on Unix systems in C, the called
> functions usually return a zero or positive value on success and -1 on
> failure, while setting a global variable (errno) to give some
> informations about the failure.
>
> What's the best way to deal with that kind of error in Ada ?
> Throwing an exception ? Returning some error code ? Passing a special
> parameter ?...
I would say : at least the “errno” strategy, is not concurrency friendly.  
if two threads of a same process commit errors, then you are in trouble  
(one may overwrite the “errno” value of the other). Exceptions would be  
cleaner for such a case (providing your “errno” is not owned by threads).

Also depends on whether or not the errors you have in mind are more or  
less predictable. As two examples : a file write error is unpredictable, a  
user input error at the command line or at a use prompt, is on the  
contrary, predictable and should be supposed to be likely to happen. For  
the former, an exception would be the best in my opinion, and for the  
latter, either an exception or a result property could be OK; while I  
would personally be on favor of a result property, because a user error is  
potentially a normal result of a user input.


-- 
“Syntactic sugar causes cancer of the semi-colons.”  [Epigrams on  
Programming — Alan J. — P. Yale University]
“Structured Programming supports the law of the excluded muddle.” [Idem]
“c++; /* this makes c bigger but returns the old value */” [Anonymous]



  parent reply	other threads:[~2011-06-11 13:31 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-31 14:01 best practice: error handling milouz
2011-05-31 17:13 ` Vinzent Hoefler
2011-05-31 17:57   ` AdaMagica
2011-06-11 13:38   ` Yannick Duchêne (Hibou57)
2011-05-31 18:08 ` Jeffrey Carter
2011-05-31 20:02   ` Dmitry A. Kazakov
2011-05-31 20:35     ` Jeffrey Carter
2011-05-31 21:40       ` Dmitry A. Kazakov
2011-06-11 13:57     ` Yannick Duchêne (Hibou57)
2011-06-11 14:07       ` Dmitry A. Kazakov
2011-06-12  5:19         ` Randy Brukardt
2011-06-11 13:48   ` Yannick Duchêne (Hibou57)
2011-06-11 13:31 ` Yannick Duchêne (Hibou57) [this message]
2011-06-11 16:12   ` Simon Wright
2011-06-11 16:26   ` Dmitry A. Kazakov
replies disabled

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