comp.lang.ada
 help / color / mirror / Atom feed
From: johnherro@aol.com (John Herro)
Subject: Re: Help with Exceptions!
Date: 1996/05/07
Date: 1996-05-07T00:00:00+00:00	[thread overview]
Message-ID: <4mnj0f$kka@newsbf02.news.aol.com> (raw)
In-Reply-To: 4mmimq$s4r@hatathli.csulb.edu


rgelb@csulb.edu (Robert Gelb) asks:
> ...when I catch an error with [an exception
> handler], how can I go back to statement
> where the error occured (or the statement
> next to it)?
     In Ada an exception handler is executed *instead of* the rest of the
procedure, function, block, etc. that raised the exception.  There's no
counterpart of Basic's RESUME or RESUME NEXT, and even a goto from an
exception handler back to the unit that raised the exception is forbidden!
 Therefore, place your exception handler in a small block, so that only a
small amount of code is skipped when the exception is raised, and place
the entire block in a loop that runs until the code executes correctly. 
For example, this program fragment will keep getting input until the user
types a valid integer; then it will go on:

Valid     : Boolean := False;
Input     : String(1 .. 80);
Input_Len : Integer;
Answer    : Integer;
...
while not Valid loop
   Put("Type an integer: ");
   Get_Line(Input, Input_Len);
   begin
      Answer := Integer'Value(Input(1 .. Input_Len));
      Valid  := True;
   exception
      when others => Put_Line("Invalid.  Please try again.");
   end;
end loop;

     Things are a bit more complicated for exceptions raised in a
*declarative* region, but most exceptions are raised in an executable
region.  There's a more detailed explanation of exceptions and exception
handlers in the Ada Tutor program, available for download at the Web and
ftp sites below my signature.
     I hope this helps.
- John Herro
Software Innovations Technology
http://members.aol.com/AdaTutor
ftp://members.aol.com/AdaTutor
     If a vegetarian is a person who eats vegetables, what does a
humanitarian eat?




  parent reply	other threads:[~1996-05-07  0:00 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-05-07  0:00 Help with Exceptions! Robert Gelb
1996-05-07  0:00 ` Steve Howard
1996-05-07  0:00   ` Robert Dewar
     [not found]   ` <4mqio5$a8b@news.sanders.lockheed.com>
1996-05-09  0:00     ` Robert L. Spooner, AD3K
1996-05-10  0:00   ` Jon S Anthony
1996-05-10  0:00     ` Robert A Duff
1996-05-07  0:00 ` John Herro [this message]
1996-05-07  0:00 ` Vincent Smeets
1996-05-14  0:00 ` Michel Gauthier
1996-05-14  0:00   ` Robert A Duff
1996-05-15  0:00     ` Norman H. Cohen
1996-05-15  0:00       ` Robert A Duff
     [not found] ` <318F94D9.35AB@io.com>
1996-05-10  0:00   ` George F.Rice
1996-05-13  0:00     ` Dave Jones
1996-05-13  0:00   ` Robert I. Eachus
1996-05-14  0:00     ` John Herro
1996-05-14  0:00       ` Robert I. Eachus
1996-05-14  0:00   ` Theodore E. Dennison
1996-05-14  0:00     ` Robert A Duff
1996-05-15  0:00 ` Michel Gauthier
1996-05-16  0:00 ` Jon S Anthony
1996-05-16  0:00   ` Robert A Duff
1996-05-16  0:00 ` Jon S Anthony
  -- strict thread matches above, loose matches on Subject: below --
1996-05-09  0:00 tmoran
replies disabled

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