From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,4819e43c270862a9,start X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!fdn.fr!gegeweb.org!aioe.org!not-for-mail From: Zachary Kline Newsgroups: comp.lang.ada Subject: Newbie Question: Integer_IO an Data_error Date: Thu, 26 Mar 2009 14:57:13 -0700 Organization: Aioe.org NNTP Server Message-ID: <873ad0ueva.fsf@babel.localdomain> NNTP-Posting-Host: Zcy3xl2b32x7uMW5ma/1dA.user.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: abuse@aioe.org NNTP-Posting-Date: Thu, 26 Mar 2009 21:56:04 +0000 (UTC) X-Notice: Filtered by postfilter v. 0.7.7 Cancel-Lock: sha1:L/1wTEGRINzoW1St08UXMf39u4U= sha1:19XEMpb+1k344IN0m3+cw9yTHWA= User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.3 (gnu/linux) Xref: g2news1.google.com comp.lang.ada:4350 Date: 2009-03-26T14:57:13-07:00 List-Id: 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.