comp.lang.ada
 help / color / mirror / Atom feed
From: Trish Cayetano <trishacayetano@gmail.com>
Subject: Re: Error "exception not permitted here" when putting EXCEPTION in a loop
Date: Sat, 18 Jul 2015 07:32:10 -0700 (PDT)
Date: 2015-07-18T07:32:10-07:00	[thread overview]
Message-ID: <f6eefaa7-eebb-4489-bda6-81bbccbfc50f@googlegroups.com> (raw)
In-Reply-To: <modlp5$rat$1@dont-email.me>

On Saturday, July 18, 2015 at 9:55:12 PM UTC+8, björn lundin wrote:
> On 2015-07-18 14:41, Trish Cayetano wrote:
> > Hello Björn, 
> > 
> > I don't need the inner loop after all.
> > I removed the inner loop but it still run in infinite loops.
> 
> 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.
> 
> 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.
> 
> Seems like a compiler bug to me, but the behavior of *text_io.get
> has surprised me before.
> 
> --
> Björn

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... 

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 := 0;

   endGame: Boolean := False;


begin

    while not endGame loop


         begin

         Ada.Text_IO.Put_Line(" | CHOOSE YOUR OPTION: 1)Shuffle 2)Pass 3)Enter Word 4)Exit ");
         Skip_Line;
         Ada.Integer_Text_IO.Get(option);
         
          exception
            when ADA.IO_EXCEPTIONS.Data_Error =>
            Ada.Text_IO.Put_Line ("Try a number from 1 to 4, Buddy");


      case option is
         when 1 =>
            Ada.Text_IO.Put_Line("Shuffle");
         when 2 =>
            Ada.Text_IO.Put_Line("Pass");
         when 3 =>
            Skip_Line;
            Ada.Text_IO.Put_Line("Enter word: ");
            Ada.Text_IO.Get_Line(GuessWord, Last);
         when 4 =>
            Ada.Text_IO.Put_Line("See you again soon!");
            endGame := true;
         when others =>
            Ada.Text_IO.Put_Line("Invalid Option");


      end case;

           
           



         end;

          end loop;



end Main;


=====

OUTPUT

C:\Users\a0284014\Desktop\ada\exception\obj\main
 | CHOOSE YOUR OPTION: 1)Shuffle 2)Pass 3)Enter Word 4)Exit 
e
1
 | CHOOSE YOUR OPTION: 1)Shuffle 2)Pass 3)Enter Word 4)Exit 
3
 | CHOOSE YOUR OPTION: 1)Shuffle 2)Pass 3)Enter Word 4)Exit 
e
Try a number from 1 to 4, Buddy
Enter word: 
e
 | CHOOSE YOUR OPTION: 1)Shuffle 2)Pass 3)Enter Word 4)Exit 
r
t
Try a number from 1 to 4, Buddy
Enter word: 
r
 | CHOOSE YOUR OPTION: 1)Shuffle 2)Pass 3)Enter Word 4)Exit 
r

  parent reply	other threads:[~2015-07-18 14:32 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-17 15:47 Error "exception not permitted here" when putting EXCEPTION in a loop Trish Cayetano
2015-07-17 15:56 ` David Botton
2015-07-17 15:58 ` G.B.
2015-07-18  8:14   ` Trish Cayetano
2015-07-18 10:08     ` Björn Lundin
2015-07-18 12:41       ` Trish Cayetano
2015-07-18 13:56         ` Björn Lundin
2015-07-18 14:08           ` Niklas Holsti
2015-07-18 14:56             ` Björn Lundin
2015-07-18 14:32           ` Trish Cayetano [this message]
2015-07-18 14:59             ` Björn Lundin
2015-07-18 16:09             ` Dennis Lee Bieber
2015-07-18 18:11               ` Niklas Holsti
2015-07-18 21:16                 ` Dennis Lee Bieber
2015-07-17 16:02 ` Björn Lundin
replies disabled

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