comp.lang.ada
 help / color / mirror / Atom feed
* Newbie Question: Integer_IO an Data_error
@ 2009-03-26 21:57 Zachary Kline
  2009-03-26 22:18 ` Tim Rowe
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Zachary Kline @ 2009-03-26 21:57 UTC (permalink / raw)


Hi all,
I'm quite new to the world of Ada, and currently trying to come to grips
with it.
I wrote for my own amusement a simple number-guessing game, which
works mostly as I intended.  The problem comes when handling
exceptions.  I can handle the case where a user typed a number too large
or too small: that's a Constraint_Error, and I just prompt again and
read another guess.  The problem comes with Data_errors: if I try to
handle that case the same way, we get a seemingly infinite loop.
I'm using Gnat 4.24 on Slackware Linux, if that matters.
Code for the procedure in question is below:
        procedure Get_Guess (Target : out Guess) is
        begin
           Put ("Your guess: ");
           Get(Target);
        exception when Constraint_Error => Put_Line ("Please, numbers from one to a hundred only.");
           Put ("Your guess: ");
           Get (Target);
           when Data_Error => Put_Line ("Numbers only, please.");
              Put ("Your guess: ");
              Get (Target);
                      when others => raise;
        end Get_Guess;
Any advice would be greatly appreciated.
Best and thanks,
Zack.
-- 
Love:
When you like to think of someone on days that begin with a morning.



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

end of thread, other threads:[~2009-03-27  8:59 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-26 21:57 Newbie Question: Integer_IO an Data_error Zachary Kline
2009-03-26 22:18 ` Tim Rowe
2009-03-26 23:57   ` Zachary Kline
2009-03-27  0:23     ` Tim Rowe
2009-03-27  0:03   ` Adam Beneschan
2009-03-27  0:19     ` Zachary Kline
2009-03-27  8:59   ` Jean-Pierre Rosen
2009-03-27  5:15 ` anon
2009-03-27  8:54 ` Dmitry A. Kazakov

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