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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,80134c7589e7b709 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-03-12 08:12:23 PST Path: supernews.google.com!sn-xit-03!supernews.com!newsfeed.wirehub.nl!feed2.onemain.com!feed1.onemain.com!newsfeed.icl.net!newspeer.clara.net!news.clara.net!server3.netnews.ja.net!newshost.central.susx.ac.uk!news.bton.ac.uk!not-for-mail From: John English Newsgroups: comp.lang.ada Subject: Re: Two questions Date: Mon, 12 Mar 2001 15:36:03 +0000 Organization: University of Brighton Message-ID: <3AACECE3.6D6E274E@bton.ac.uk> References: NNTP-Posting-Host: straumli.it.bton.ac.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: saturn.bton.ac.uk 984411328 5182 193.62.183.204 (12 Mar 2001 15:35:28 GMT) X-Complaints-To: news@bton.ac.uk NNTP-Posting-Date: 12 Mar 2001 15:35:28 GMT X-Mailer: Mozilla 4.5 [en] (Win95; I) X-Accept-Language: en Xref: supernews.google.com comp.lang.ada:5642 Date: 2001-03-12T15:35:28+00:00 List-Id: "chris.danx" wrote: > > Hi, > two questions, one on exceptions and one on objects or tagged types. > > Where exactly can i put an exception handler? I read in JE's book that you > can put them in loop ... end loop statements after an exit statement. You've misread the book then, or written "can" instead of "can't" by mistake... > I > normally put handlers at the end of a routine, and i was supprised to find > you could put them elsewhere. What i want to know is where else can i put > them? In a while loop? In a for loop? In an if? ... etc. Inside a begin...end block (which can go inside a loop or whatever), e.g. like this: loop begin Put("Enter an integer: "); Get(X); exit; -- get out of loop if this line is reached exception when Constraint_Error | Data_Error => Put_Line ("Error in input -- please try again"); Skip_Line; -- end up here if "Get" fails, end; -- so don't exit from the loop end loop; (This is the example from p.40 of my book.) > The second is to do with tagged types. Sometimes it is suggested that you > put your 'create routine' -- the initialisation routine -- in a nested > package. Others suggest putting it in the same package as the tagged type. > > Example > > package something_cool is > > type cool is tagged private; > > package constructor is > > procedure create (c : out cool; ... ... ); > > end constructor; > > private > ... > ... > > end something_cool; > > or > > package something_cool is > > type cool is tagged private; > > procedure create (c : out cool; ... ... ); > > private > ... > ... > > end something_cool; > > What's the difference? Where should i use method 1 and where should i use > method 2? Generally, use the first. If you use the second approach, "create" is inherited by types derived from Cool, but it may well need extra parameters for a derived type... so you end up with two versions of Create, one with the old set of parameters (which will presumably do incomplete initialisation) which you might call accidentally. The second technique just avoids making Create a primitive of Cool, so it isn't inherited. (This is discussed in section 14.6 of my book.) ----------------------------------------------------------------- John English | mailto:je@brighton.ac.uk Senior Lecturer | http://www.it.bton.ac.uk/staff/je Dept. of Computing | ** NON-PROFIT CD FOR CS STUDENTS ** University of Brighton | -- see http://burks.bton.ac.uk -----------------------------------------------------------------