From: "Peter C. Chapin" <pcc482719@gmail.com>
Subject: Re: Strategies with SPARK which does not support exceptions
Date: Thu, 17 Jun 2010 18:47:18 -0400
Date: 2010-06-17T18:47:18-04:00 [thread overview]
Message-ID: <4c1aa551$0$2390$4d3efbfe@news.sover.net> (raw)
In-Reply-To: 4c1a7d49$0$2994$ba4acef3@reader.news.orange.fr
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
next prev parent reply other threads:[~2010-06-17 22:47 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-17 15:33 Strategies with SPARK which does not support exceptions Yannick Duchêne (Hibou57)
2010-06-17 17:11 ` Warren
2010-06-17 18:19 ` Yannick Duchêne (Hibou57)
2010-06-21 13:31 ` Warren
2010-06-21 14:10 ` Alexandre K
2010-06-17 19:54 ` Pascal Obry
2010-06-17 22:47 ` Peter C. Chapin [this message]
2010-06-18 6:07 ` Claude
2010-06-18 8:06 ` Phil Thornley
2010-06-18 8:49 ` Martin
2010-06-18 17:16 ` mockturtle
2010-06-18 21:51 ` Alexandre K
2010-06-22 17:01 ` Phil Clayton
2010-06-22 23:14 ` Claude
2010-06-23 16:22 ` Warren
2010-06-24 3:24 ` Claude
2010-06-28 13:14 ` Warren
2010-06-29 8:39 ` Stephen Leake
2010-06-29 20:05 ` Randy Brukardt
2010-06-29 20:49 ` Georg Bauhaus
2010-06-30 5:08 ` Simon Wright
2010-06-30 8:17 ` stefan-lucks
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox