comp.lang.ada
 help / color / mirror / Atom feed
From: dvdeug@x8b4e53cd.dhcp.okstate.edu (David Starner)
Subject: Re: Problem with function return
Date: 2000/04/02
Date: 2000-04-02T00:00:00+00:00	[thread overview]
Message-ID: <8c87g4$8201@news.cis.okstate.edu> (raw)
In-Reply-To: 38e7a0c8$0$17676@businessnews.de.uu.net

On Sun, 2 Apr 2000 21:34:59 +0200, Amgarp <PhyrePhox@firemail.de> wrote:
>Hi,
>
>please help me with the following Problem:
>
>Main programm:
>
>type color is (red,gree,blue);
>
>col:color;
>
>col:=some_function(parameter);
>
>Now, "some_function" returns of course a color type,
>but when the parameter is bad(e.g. an empty string), an exception will be
>raised.
>
>What should the function return then?

What is the function? What is the problem?

Possible solutions:

(a) Make type color is (none, red, green, blue) and return none.
It's probably not appropriate in this context, but I can't really
tell. Cf. IEEE 745 floating point numbers for an example (NaN & Inf).

(b) Raise or propogate an exception. Proabably your best solution
in this case. 

(c) Check the input, and only call some_function if the input is
good. I don't like this one, as some_function should still check
the data itself, as long as it takes unstructured data. 

(d) Assert that the data is correct (e.g. using GNAT's pragma Assert)
and if it's not, print an error message and quit. Only appropriate
if parameter does not come from the output and must be correct no
matter what comes in.

Really, the problem admits of many many answers. If you frame the
question in specifics, I can give a specific answer.

-- 
David Starner - dstarner98@aasaa.ofe.org
Only a nerd would worry about wrong parentheses with
square brackets. But that's what mathematicians are.
   -- Dr. Burchard, math professor at OSU




  reply	other threads:[~2000-04-02  0:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-04-02  0:00 Problem with function return Amgarp
2000-04-02  0:00 ` David Starner [this message]
2000-04-03  0:00 ` A. Logue
2000-04-02  0:00   ` Ray Blaak
2000-04-03  0:00     ` Robert Dewar
2000-04-03  0:00   ` Robert Dewar
2000-04-03  0:00     ` Mats Weber
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox