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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,5c3042563529d4f3,start X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,CP1252 Received: by 10.68.129.169 with SMTP id nx9mr39796pbb.8.1326408169180; Thu, 12 Jan 2012 14:42:49 -0800 (PST) Path: lh20ni175280pbb.0!nntp.google.com!news2.google.com!postnews.google.com!z12g2000yqm.googlegroups.com!not-for-mail From: John McCormick Newsgroups: comp.lang.ada Subject: Data_Error and Enumeration_IO Date: Thu, 12 Jan 2012 14:41:07 -0800 (PST) Organization: http://groups.google.com Message-ID: <3f3d626a-1b8c-49af-aa85-9e586029a817@z12g2000yqm.googlegroups.com> NNTP-Posting-Host: 134.161.242.221 Mime-Version: 1.0 X-Trace: posting.google.com 1326408169 13325 127.0.0.1 (12 Jan 2012 22:42:49 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 12 Jan 2012 22:42:49 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: z12g2000yqm.googlegroups.com; posting-host=134.161.242.221; posting-account=jVm7MAoAAABZ69ylB7L9PjZAVQg4j4fC User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-Header-Order: ARLUEHNKC X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C; .NET4.0E),gzip(gfe) Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Date: 2012-01-12T14:41:07-08:00 List-Id: I need some assistance in understanding the consumption of input characters when a Data_Error is raised during the input of an enumeration value. My experiments show that there is a different behavior depending on whether the illegal input consists of alphabetic characters or digits. Here is a short example to illustrate my ingorance. The following code fragment reads in an enumeration value using a Data_Error exception to catch invalid entries. type Choice_Type is (Encode, Decode); package Choice_IO is new Ada.Text_IO.Enumeration_IO (Enum =3D> Choice_Type); loop Ada.Text_IO.Put_Line ("Would you like to encode or decode a message"); begin Choice_IO.Get (Choice); exit; -- the data validation loop exception when Ada.IO_Exceptions.Data_Error =3D> Ada.Text_IO.Put_Line ("Invalid entry. Please enter Encode or Decode."); Ada.Text_IO.Skip_Line; -- Skip over the offending data end; end loop; This code is my usual pattern for data validation and works for whatever invalid input I enter. However, when my students leave out the call to Skip_Line in the Data_Error exception handler the behavior depends on the actual value entered. It still works as desired when the input is alphabetic characters such as =93abc=94. But when the input consists of digits such as =93123=94 the loop becomes infinite, repeating the prompt and error message. It appears to me that the call to Choice_IO.Get consumes the alphabetic input but does not consume the digit input leaving it available for the next call to Get. I could not find anything in the language reference manual about how Enumeration_IO consumes input characters when Data_Error is raised. Can anyone give me an explanation? Is it implementation defined? I am running GNAT GPL 2011.