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 01:14:29 -0700 (PDT)
Date: 2015-07-18T01:14:29-07:00	[thread overview]
Message-ID: <ec2039a5-9981-4d1b-9fcf-f92cd4e1abfb@googlegroups.com> (raw)
In-Reply-To: <mob8k0$jom$1@dont-email.me>

On Friday, July 17, 2015 at 11:58:18 PM UTC+8, G.B. wrote:
> On 17.07.15 17:47, Trish Cayetano wrote:
> > Hi,
> >
> > I am getting error "exception not permitted here" when running below in a loop.
> > Well it runs if I put it outside the loop but I need it inside the loop...
> >
> >             exception
> >              when ADA.IO_EXCEPTIONS.DATA_ERROR =>
> >              Ada.Text_IO.Put_Line ("Try a number from 1 to 4, Buddy");
> >
> > Thanks in advance for your help...
> >
> 
> does it look like
> 
>   loop
>      ...
>     exception ...
>      ...
>   end loop
> 
> If so, then note that "exception" must be in a block,
> such as a procedure body, or a block statement (LRM 5.6):
> 
> 
>    loop
>      begin
>        ...  -- handled sequence of statements
>      exception ...
>      ...
>      end;
>    end loop
> 
> More complete examples would help reducing guess work.

Thanks, David and GB.
It still does not work... 
Here is my own code (i removed the functions and others)... Sorry I am really new to Ada. I actually tried also to put another loop and added declare, begin and end. It hang after I ran. And when I terminated the process, it looks like it ran infinitely in loops. 

   
===== 
--start of code

   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

      loop
         begin

      Ada.Text_IO.Put_Line(" | CHOOSE YOUR OPTION: 1)Shuffle 2)Pass 3)Enter Word 4)Exit ");
      Ada.Integer_Text_IO.Get(option);

      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;

            exception
            when ADA.IO_EXCEPTIONS.Data_Error =>
            Ada.Text_IO.Put_Line ("Try a number from 1 to 4, Buddy");




         end;
          end loop;
      end loop;


end Main;



--end of code
==============
RESULT:

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

--retracted repeats
[2015-07-18 16:11:13] process exited with status 1, elapsed time: 19.58s

  reply	other threads:[~2015-07-18  8:14 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 [this message]
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
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