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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,c4bd2a19251049b1 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,UTF8 Path: g2news2.google.com!news3.google.com!feeder3.cambriumusenet.nl!feed.tweaknews.nl!194.134.4.91.MISMATCH!news2.euro.net!feeder.news-service.com!94.75.214.39.MISMATCH!aioe.org!.POSTED!not-for-mail From: =?utf-8?Q?Yannick_Duch=C3=AAne_=28Hibou57?= =?utf-8?Q?=29?= Newsgroups: comp.lang.ada Subject: Re: best practice: error handling Date: Sat, 11 Jun 2011 15:31:39 +0200 Organization: Ada @ Home Message-ID: References: <0b95a2a1-6e3d-4ad1-a832-e3099a9bce37@v8g2000yqb.googlegroups.com> NNTP-Posting-Host: fGpkzlUfcOSQVUiZJOXhgg.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes Content-Transfer-Encoding: Quoted-Printable X-Complaints-To: abuse@aioe.org User-Agent: Opera Mail/11.11 (Linux) X-Notice: Filtered by postfilter v. 0.8.2 Xref: g2news2.google.com comp.lang.ada:20718 Date: 2011-06-11T15:31:39+02:00 List-Id: Le Tue, 31 May 2011 16:01:19 +0200, milouz a = =C3=A9crit: > 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 =E2=80=9Cerrno=E2=80=9D strategy, is not conc= urrency friendly. = if two threads of a same process commit errors, then you are in trouble = = (one may overwrite the =E2=80=9Cerrno=E2=80=9D value of the other). Exce= ptions would be = cleaner for such a case (providing your =E2=80=9Cerrno=E2=80=9D is not o= wned 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. -- = =E2=80=9CSyntactic sugar causes cancer of the semi-colons.=E2=80=9D [Ep= igrams on = Programming =E2=80=94 Alan J. =E2=80=94 P. Yale University] =E2=80=9CStructured Programming supports the law of the excluded muddle.= =E2=80=9D [Idem] =E2=80=9Cc++; /* this makes c bigger but returns the old value */=E2=80=9D= [Anonymous]