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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.13.232.198 with SMTP id r189mr22386490ywe.35.1437229931063; Sat, 18 Jul 2015 07:32:11 -0700 (PDT) X-Received: by 10.50.126.72 with SMTP id mw8mr51661igb.8.1437229931032; Sat, 18 Jul 2015 07:32:11 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!news.glorb.com!peer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!z61no1826727qge.0!news-out.google.com!t2ni14406igk.0!nntp.google.com!qs7no7313901igc.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sat, 18 Jul 2015 07:32:10 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=112.203.251.230; posting-account=7jTbjwoAAADuqLe9GO_M9l_Emer5tqxR NNTP-Posting-Host: 112.203.251.230 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Error "exception not permitted here" when putting EXCEPTION in a loop From: Trish Cayetano Injection-Date: Sat, 18 Jul 2015 14:32:11 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Received-Bytes: 4326 X-Received-Body-CRC: 332250950 Xref: news.eternal-september.org comp.lang.ada:26877 Date: 2015-07-18T07:32:10-07:00 List-Id: On Saturday, July 18, 2015 at 9:55:12 PM UTC+8, bj=F6rn lundin wrote: > On 2015-07-18 14:41, Trish Cayetano wrote: > > Hello Bj=F6rn,=20 > >=20 > > I don't need the inner loop after all. > > I removed the inner loop but it still run in infinite loops. >=20 > it runs fine as long as you do not enter a non-digit. > Then it seems like the call to > Ada.Integer_Text_IO.Get(option); > does not clear the buffer. >=20 > if fed a character, Data_error is raised - which is correct. > But the next time the code enters the loop, it seems it does > not wait for input again. > It raises the data_error again, and the infinite loop is there. >=20 > Seems like a compiler bug to me, but the behavior of *text_io.get > has surprised me before. >=20 > -- > Bj=F6rn Well which reminds me! I added a SKIP_LINE... The expected output is close.= .. It shows the exception error every other input... it waits for 2 inputs = and then 1 input and then 2...=20 REVISED with Ada.Text_IO; use Ada.Text_IO; with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; with Ada.Numerics.Discrete_Random; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; with Ada.Text_IO.Unbounded_IO; use Ada.Text_IO.Unbounded_IO; with Ada.IO_Exceptions; use Ada.IO_Exceptions; procedure Main is GuessWord : String(1..20); last: Natural; option : Integer :=3D 0; endGame: Boolean :=3D False; begin while not endGame loop begin Ada.Text_IO.Put_Line(" | CHOOSE YOUR OPTION: 1)Shuffle 2)Pass 3)En= ter Word 4)Exit "); Skip_Line; Ada.Integer_Text_IO.Get(option); =20 exception when ADA.IO_EXCEPTIONS.Data_Error =3D> Ada.Text_IO.Put_Line ("Try a number from 1 to 4, Buddy"); case option is when 1 =3D> Ada.Text_IO.Put_Line("Shuffle"); when 2 =3D> Ada.Text_IO.Put_Line("Pass"); when 3 =3D> Skip_Line; Ada.Text_IO.Put_Line("Enter word: "); Ada.Text_IO.Get_Line(GuessWord, Last); when 4 =3D> Ada.Text_IO.Put_Line("See you again soon!"); endGame :=3D true; when others =3D> Ada.Text_IO.Put_Line("Invalid Option"); end case; =20 =20 end; end loop; end Main; =3D=3D=3D=3D=3D OUTPUT C:\Users\a0284014\Desktop\ada\exception\obj\main | CHOOSE YOUR OPTION: 1)Shuffle 2)Pass 3)Enter Word 4)Exit=20 e 1 | CHOOSE YOUR OPTION: 1)Shuffle 2)Pass 3)Enter Word 4)Exit=20 3 | CHOOSE YOUR OPTION: 1)Shuffle 2)Pass 3)Enter Word 4)Exit=20 e Try a number from 1 to 4, Buddy Enter word:=20 e | CHOOSE YOUR OPTION: 1)Shuffle 2)Pass 3)Enter Word 4)Exit=20 r t Try a number from 1 to 4, Buddy Enter word:=20 r | CHOOSE YOUR OPTION: 1)Shuffle 2)Pass 3)Enter Word 4)Exit=20 r