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-09 12:59:13 PST Path: supernews.google.com!sn-xit-02!sn-xit-04!supernews.com!europa.netcrusader.net!4.1.16.34!cpk-news-hub1.bbnplanet.com!cambridge1-snf1.gtei.net!news.gtei.net!homer.alpha.net!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada References: Subject: Re: Two questions X-Newsreader: Microsoft Outlook Express 4.72.3612.1700 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3719.2500 Message-ID: Date: Fri, 9 Mar 2001 14:56:00 -0600 NNTP-Posting-Host: 156.46.62.124 X-Complaints-To: abuse@alpha.net X-Trace: homer.alpha.net 984171552 156.46.62.124 (Fri, 09 Mar 2001 14:59:12 CST) NNTP-Posting-Date: Fri, 09 Mar 2001 14:59:12 CST Xref: supernews.google.com comp.lang.ada:5582 Date: 2001-03-09T14:56:00-06:00 List-Id: chris.danx wrote in message ... >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. 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. You can't add a handler to a loop, for instance. But, you can put an exception handler on a block. And a block is a statement. So, effectively, you can put an exception handler anywhere you can put a statement. For instance: loop begin exception .... end; end loop; >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? When you have the nested package, the constructor is not inherited when the type is derived. (In RMese, it isn't a primitive operation of the type.) Typically, each constructor has a separate set of parameters, and you don't want the same parameters on the constructor for each type. Ada 95 doesn't let you delete operations that are inherited, so you have to prevent them from being inherited in the first place. The alternative (which we use in Claw) is to override *all* inherited constructors, and either make them work or raise an exception. But that only works well with a shallow inheritance structure; a deeper structure could end up with dozens of useless constructors inherited. Randy.