comp.lang.ada
 help / color / mirror / Atom feed
From: Zachary Kline <kline.zachary@gmail.com>
Subject: Newbie Question: Integer_IO an Data_error
Date: Thu, 26 Mar 2009 14:57:13 -0700
Date: 2009-03-26T14:57:13-07:00	[thread overview]
Message-ID: <873ad0ueva.fsf@babel.localdomain> (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.



             reply	other threads:[~2009-03-26 21:57 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-26 21:57 Zachary Kline [this message]
2009-03-26 22:18 ` Newbie Question: Integer_IO an Data_error 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
replies disabled

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