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: g2news1.google.com!news3.google.com!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:48:38 +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: g2news1.google.com comp.lang.ada:19749 Date: 2011-06-11T15:48:38+02:00 List-Id: Le Tue, 31 May 2011 20:08:38 +0200, Jeffrey Carter = a =C3=A9crit: > The correct way to handle this is for the function to return a variant= = > record: > > type Index_Result (Found : Boolean :=3D False) is record > case Found is > when False =3D> > null; > when True =3D> > Index : Positive; > end case; > end record; That's an idiom I also use with SML (I feel to remember there is a = dedicated name for that idiom, but I forget what it is this name), as = access to the result is automatically constrained to whether or not the = = function succeed. But while this is good for request-like function (like= = get the item with this or that property), this come to be less handy whe= n = many and many functions or procedure return a common type may also retur= n = error, because you end to as many type definition. Another case is the if-previous-succeed-then-go-on-else-bypass idiom. = Multiple procedure get an in/out boolen parameter. If on input, the = parameter is False, then the procedure bypass its own process, if the = input parameter is True, the procedure do its job and set the parameter = to = False on output if ever it fails somewhere. This is a useful idiom with = = SPARK which does not allow exceptions. Combined with that strategy, a = wrapper type would lead to a mess. -- = =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]