From: Jean-Pierre Rosen <rosen@adalog.fr>
Subject: Re: Newbie Question: Integer_IO an Data_error
Date: Fri, 27 Mar 2009 09:59:22 +0100
Date: 2009-03-27T09:59:22+01:00 [thread overview]
Message-ID: <gh4iqg.09i.ln@hunter.axlog.fr> (raw)
In-Reply-To: <Wp6dnQTpg6rFYlbUnZ2dnUVZ8tudnZ2d@posted.plusnet>
Tim Rowe a �crit :
> Zachary Kline wrote:
>> The problem comes with Data_errors: if I try to
>> handle that case the same way, we get a seemingly infinite loop.
>
>
> I'm an Ada newbie too, but the first thing I wonder is what Get does
> with the input characters if they don't match the expected type. I
> wonder whether it leaves them on the input stream -- in which case
> subsequent attempts to read the input will try to read the same
> characters each time. Until somebody who knows what they're talking
> about comes along (won't be long) I'd try doing a string Get after a
> failed numeric get, to see what's still in the input stream.
When a character is incorrect, the current position stays on it, to
allow you to do a Get(Char) and see what happened. OTOH, it means that
you must do a skip_line to get rid of the remaining of the line, and get
a fresh one. A typical reading loop is:
loop
begin
Get (N);
exit; -- OK, no exception
exception
when Data_Error =>
Skip_Line;
Put_Line ("Error, try again");
end;
end loop;
--
---------------------------------------------------------
J-P. Rosen (rosen@adalog.fr)
Visit Adalog's web site at http://www.adalog.fr
next prev parent reply other threads:[~2009-03-27 8:59 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-26 21:57 Newbie Question: Integer_IO an Data_error Zachary Kline
2009-03-26 22:18 ` Tim Rowe
2009-03-26 23:57 ` Zachary Kline
2009-03-27 0:23 ` Tim Rowe
2009-03-27 0:03 ` Adam Beneschan
2009-03-27 0:19 ` Zachary Kline
2009-03-27 8:59 ` Jean-Pierre Rosen [this message]
2009-03-27 5:15 ` anon
2009-03-27 8:54 ` Dmitry A. Kazakov
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox