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.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,dc9636dd2392f5bd X-Google-Attributes: gid103376,public From: dvdeug@x8b4e53cd.dhcp.okstate.edu (David Starner) Subject: Re: Problem with function return Date: 2000/04/02 Message-ID: <8c87g4$8201@news.cis.okstate.edu>#1/1 X-Deja-AN: 605761440 References: <38e7a0c8$0$17676@businessnews.de.uu.net> Organization: Oklahoma State University User-Agent: slrn/0.9.6.2 (Linux) Reply-To: dstarner98@aasaa.ofe.org Newsgroups: comp.lang.ada Date: 2000-04-02T00:00:00+00:00 List-Id: On Sun, 2 Apr 2000 21:34:59 +0200, Amgarp 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