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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,4819e43c270862a9 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!news.glorb.com!news2.glorb.com!wn11feed!worldnet.att.net!bgtnsc05-news.ops.worldnet.att.net.POSTED!53ab2750!not-for-mail Newsgroups: comp.lang.ada From: anon@anon.org (anon) Subject: Re: Newbie Question: Integer_IO an Data_error Reply-To: no to spamers (No@email.given.org) References: <873ad0ueva.fsf@babel.localdomain> X-Newsreader: IBM NewsReader/2 2.0 Message-ID: Date: Fri, 27 Mar 2009 05:15:24 GMT NNTP-Posting-Host: 12.64.60.243 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc05-news.ops.worldnet.att.net 1238130924 12.64.60.243 (Fri, 27 Mar 2009 05:15:24 GMT) NNTP-Posting-Date: Fri, 27 Mar 2009 05:15:24 GMT Organization: AT&T Worldnet Xref: g2news1.google.com comp.lang.ada:4357 Date: 2009-03-27T05:15:24+00:00 List-Id: You must use Skip_Line procedure and remove all Gets within the exception handlers! with Ada.Text_IO ; use Ada.Text_IO ; function test return integer is -- just for the fun of it type Guess is new Integer ; package I_IO is new Ada.Text_IO.Integer_IO ( Guess ) ; use I_IO ; procedure Get_Guess (Target : out Guess) is begin new_line ; Put ("Your guess: "); Get(Target); exception when Constraint_Error => Put_Line ("Please, numbers from one to a hundred only."); when Data_Error => Put_Line ("Numbers only, please."); when others => raise ; end Get_Guess; Temp : Guess := 0 ; begin loop begin Get_Guess ( Temp ) ; Put_Line ("Done"); exit when temp = 6 ; exception when others => Put_Line ("Bad Data"); return -7 ; end ; Skip_Line ; end loop ; return 0 ; exception when others => return -1 ; end test ; In <873ad0ueva.fsf@babel.localdomain>, Zachary Kline writes: >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.