comp.lang.ada
 help / color / mirror / Atom feed
From: John English <je@bton.ac.uk>
Subject: Re: Two questions
Date: Mon, 12 Mar 2001 15:36:03 +0000
Date: 2001-03-12T15:35:28+00:00	[thread overview]
Message-ID: <3AACECE3.6D6E274E@bton.ac.uk> (raw)
In-Reply-To: Eg9q6.4382$pR3.821782@news2-win.server.ntlworld.com

"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
-----------------------------------------------------------------



  parent reply	other threads:[~2001-03-12 15:36 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-03-09 18:27 Two questions chris.danx
2001-03-09 20:22 ` Mark Lundquist
2001-03-09 20:56 ` Randy Brukardt
2001-03-12 15:36 ` John English [this message]
2001-03-12 18:11   ` chris.danx
  -- strict thread matches above, loose matches on Subject: below --
2002-07-04 22:25 Mark
2002-07-04 22:40 ` Jeffrey Creem
2001-03-12 10:59 Christoph Grein
2001-03-12 17:43 ` Stephen Leake
1996-11-09  0:00 tmoran
1996-11-11  0:00 ` Adam Beneschan
1996-11-13  0:00 ` Richard A. O'Keefe
1996-11-07  0:00 Ding-yuan Sheu
1996-11-07  0:00 ` Robert Dewar
1996-11-08  0:00 ` Norman H. Cohen
1996-11-08  0:00 ` Jon S Anthony
1996-11-08  0:00 ` Robert I. Eachus
1996-05-01  0:00 Bernard Banner
1996-05-01  0:00 W. Wesley Groleau (Wes)
1996-05-01  0:00 Ed Seidewitz
1989-04-11 13:32 Piercarlo Grandi
1989-04-14 17:14 ` callen
1989-03-30 11:53 Piercarlo Grandi
1989-04-13  0:46 ` Paul Stachour
1989-03-29  9:16 HansM
1989-03-29 18:35 ` Michael Peirce
1989-03-31 13:10 ` stt
1989-03-31 18:59 ` Scott Simpson
1989-04-03 14:44 ` callen
replies disabled

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