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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,ec21c3c7cdc7ff3e X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news4.google.com!news2.volia.net!news.germany.com!news.ispa.de!news.jacob-sparre.dk!pnx.dk!not-for-mail From: Jacob Sparre Andersen Newsgroups: comp.lang.ada Subject: Re: Handling invalid objects Date: Sat, 18 Mar 2006 09:57:24 +0100 Organization: Jacob's private Usenet server Message-ID: References: <1142279908.327131.230200@j52g2000cwj.googlegroups.com> <41LSf.4126$TK2.1805@trnddc07> NNTP-Posting-Host: dhcp108.dhcp.nbi.dk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: jacob-sparre.dk 1142672245 32028 172.24.5.108 (18 Mar 2006 08:57:25 GMT) X-Complaints-To: sparre@jacob-sparre.dk NNTP-Posting-Date: Sat, 18 Mar 2006 08:57:25 +0000 (UTC) User-Agent: Gnus/5.110004 (No Gnus v0.4) Emacs/21.4 (gnu/linux) Cancel-Lock: sha1:XxPjE5QpQQTTjzbwmt/cfvzijMc= Xref: g2news1.google.com comp.lang.ada:3425 Date: 2006-03-18T09:57:24+01:00 List-Id: Justin Gombos wrote: > The 'Valid attribute exists to be able to handle abnormal objects. > > Here's a concrete example. Suppose I have: > > type clock_type is mod 12; > > function hour_of_day return clock_type; > > If hour_of_day gets called and for whatever reason I cannot return > an hour_of_day, the caller needs to know that. Exceptions are a > poor choice. The quality and style guide advises against them for a > good reason; exceptions are like gotos - and produce a questionable > state. It would be more graceful for me to return an invalid value > (like -1), so my caller can simply do a 'Valid to discover whether > the operation was successful. No. The way to do that is to have proper values for all the states you want to handle, i.e.: type Hours is mod 12; type Clock_Type (Is_Set : Boolean := False) is new record case Is_Set is when True => Time : Hours; when False => null; end case; end record; Greetings, Jacob -- ACRONYM: A Contrived Reduction Of Nomenclature Yielding Mnemonics