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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,e646052dc594401f X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news1.google.com!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!nx02.iad01.newshosting.com!newshosting.com!novia!news-xxxfer.readnews.com!news-out.readnews.com!postnews3.readnews.com!not-for-mail Message-Id: <4c1aa551$0$2390$4d3efbfe@news.sover.net> From: "Peter C. Chapin" Subject: Re: Strategies with SPARK which does not support exceptions Newsgroups: comp.lang.ada Date: Thu, 17 Jun 2010 18:47:18 -0400 References: <4c1a7d49$0$2994$ba4acef3@reader.news.orange.fr> User-Agent: KNode/0.10.9 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit Organization: SoVerNet (sover.net) NNTP-Posting-Host: 985e1196.news.sover.net X-Trace: DXC=Zm[kaa4M[6U54WfImF>H4_K6_LM2JZB_SlXHJXGi>>6Y:WUUlR<856_7g\fPnKXZ1R9gU_X]VUSMZ X-Complaints-To: abuse@sover.net Xref: g2news2.google.com comp.lang.ada:12780 Date: 2010-06-17T18:47:18-04:00 List-Id: Pascal Obry wrote: > There is no exception, so not error to check... I don't see the point of > the Ok variable. > > I'm probably missing something, can you clarify? I think what Yannick is talking about is something like this: -- Full Ada: procedure Complicated_Operation(X : in Some_Type); -- Raises Operation_Failed if there is an error. -- SPARK: procedure Complicated_Operation(X : in Some_Type; Ok : out Boolean); -- Writes True into 'Ok' if successful, otherwise False. Now instead of having a nice exception handler you have to do things like Complicated_Operation(Argument, Success); if not Success then -- Deal with failure here. else -- Continue with the program here. end if; Of course this gets a bit ugly if you do lots of operations that might fail. One thing I've done is something like this --SPARK: procedure Complicated_Operation(X : in Some_Type; Ok : in out Boolean); -- Writes False into 'Ok' if failed; otherwise no change to 'Ok'. Now I can do Ok : Boolean := True; ... Complicated_Operation(Argument_1, Ok); Complicated_Operation(Argument_2, Ok); Complicated_Operation(Argument_3, Ok); if not Ok then -- A failure occurred somewhere above. end if; Of course this only works if it's acceptable to continue the program after a failure of one of the earlier operations. Obviously that's not always going to be the case. Peter