comp.lang.ada
 help / color / mirror / Atom feed
* Exception problem
@ 1997-02-18  0:00 Larry Coon
  1997-02-18  0:00 ` Michael Feldman
                   ` (4 more replies)
  0 siblings, 5 replies; 19+ messages in thread
From: Larry Coon @ 1997-02-18  0:00 UTC (permalink / raw)



Ada beginner here...

The intent of the following code is to loop until valid input is 
provided:

declare
   X: Positive;
   package Int_IO is new Integer_IO (Integer);
   use Int_IO;
begin
   loop
      begin
         Put ("Enter a positive number: ");
         Get (X);
         exit; -- No exception, so input was valid.
      exception
         when Constraint_Error =>
            Put_Line ("Entry must be positive.  Try again.");
         when Data_Error =>
            Put_Line ("Entry must be a number.  Try again.");
      end;
   end loop;
   -- Procesing for X....
end;

The idea is that if input is not valid an exception will be thrown, the 
appropriate message will be displayed, and the code will loop back to 
the prompt.  If no exception is thrown the input is valid, and the exit 
statement take the program out of the loop.

This code handles non-positive numeric input (eg: 0 or -3) correctly.  
But when I give it non-numeric input (eg: C), it displays the "Entry 
must be a number.  Try again" message repeatedly and never stops for 
input again.

Compiler is Thomson Academic ObjectAda V7.0.171 in Win 95.

I'd appreciate any insight.

Larry Coon
University of California
larry@fs2.assist.uci.edu




^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~1997-03-12  0:00 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-02-18  0:00 Exception problem Larry Coon
1997-02-18  0:00 ` Michael Feldman
1997-02-19  0:00   ` Larry Coon
1997-02-19  0:00 ` Keith Allan Shillington
1997-02-19  0:00 ` David C. Hoos, Sr.
1997-02-19  0:00   ` Larry Coon
1997-02-19  0:00   ` Robert Dewar
1997-02-19  0:00 ` Joerg Rodemann
1997-02-19  0:00   ` Mats Weber
1997-02-22  0:00 ` Arthur Evans Jr
1997-02-24  0:00   ` Larry Coon
1997-02-24  0:00     ` Larry Kilgallen
1997-02-24  0:00       ` Larry Coon
1997-02-25  0:00         ` Fergus Henderson
1997-02-25  0:00     ` Do-While Jones
1997-03-09  0:00       ` John Volan
1997-03-09  0:00         ` Robert Dewar
1997-03-12  0:00         ` Keith Thompson
1997-02-25  0:00   ` Robert I. Eachus

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