comp.lang.ada
 help / color / mirror / Atom feed
From: Warren <ve3wwg@gmail.com>
Subject: Re: Strategies with SPARK which does not support exceptions
Date: Thu, 17 Jun 2010 17:11:29 +0000 (UTC)
Date: 2010-06-17T17:11:29+00:00	[thread overview]
Message-ID: <Xns9D9A86312F108WarrensBlatherings@81.169.183.62> (raw)
In-Reply-To: op.vegat3qjule2fv@garhos

=?utf-8?Q?Yannick_Duch=C3=AAne_=28Hibou57?= =?utf-8?Q?=29?= expounded in
news:op.vegat3qjule2fv@garhos: 

> When I use SPARK, or even when I don't use SPARK while I still have
> SPARK  design style in mind (even with Pascal which I still use), I
> have like any  one else, to forget about exceptions.
> 
> The only one thing which seems simple and clean enough I could figure,
> is  to use a Boolean variable, named "OK", and a sequence of "if
> OK then" statements. ...
> 
> Although this seems clean and maintainable enough to me so far, I was 
> still wondering how other people deal with this (and may be by the
> way, I  may have comment about why my way could be bad in some way).

While I'm not a SPARK user, a similar issue exists when writing
C code (although you can implement an exception with longjmp()).

In C, the best approach seems to be to have a defined set of
error/status codes to return. Often the errno values (e.g. EINVAL)
are used. But you can define a better enum set dedicated to 
your application's specific needs.

In Ada, you can vastly improve upon that using a "real" enumerated
type.  You can then define as many enum types as you need for
each class of function/procedures.

I suggest this because the calling program usually needs to
know "why" the call failed. 

It is often not sufficient to simply know that OK is false. 
For example, wouldn't it be nice for the user to know that 
the open failed because of permissions, instead of the file
not existing. 

Warren



  reply	other threads:[~2010-06-17 17:11 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 [this message]
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
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