comp.lang.ada
 help / color / mirror / Atom feed
From: Niklas Holsti <niklas.holsti@tidorum.invalid>
Subject: Re: Error "exception not permitted here" when putting EXCEPTION in a loop
Date: Sat, 18 Jul 2015 17:08:23 +0300
Date: 2015-07-18T17:08:23+03:00	[thread overview]
Message-ID: <d0v4uoF1efoU1@mid.individual.net> (raw)
In-Reply-To: <modlp5$rat$1@dont-email.me>

On 15-07-18 16:56 , 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.

It is specified in the LRM that if the Get for Integer_IO encounters a 
character that cannot be part of the integer number, it stops at that 
point and does not "pass" that character. This means that one can read 
the integer 123 from the text "123ABC" and then read the string "ABC"; 
the Get for the integer does not "consume" the "A".

If you want to "clear the buffer", you should call Skip_Line, also in 
the exception handler.

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
       .      @       .


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