From: "David H. Haley" <dhaley@onlink.net>
Subject: Help With Ada_Io and Exceptions
Date: 1997/05/29
Date: 1997-05-29T00:00:00+00:00 [thread overview]
Message-ID: <338E3601.3E7E@onlink.net> (raw)
In-Reply-To: 338CEEA4.93867B6D@iinet.net.au
-- I'm having a bit of a problem with Ada_Io.get after a Data_Error is
raised,
-- and am wondering if anyone can shed some light on this.
-- Many thanks in advance......
WITH Ada_Io; USE Ada_Io;
WITH Text_Io; USE Text_Io;
--
-- adapted from ADA as a second language
-- by Norman H. Cohen Page 485
--
-- The purpose of this procedure is to check to see whether or not
-- the user has input valid data - i.e. an integer is expected; however,
-- if the user enters a character string e.g. "t" or "test" in lieu of
-- the expected integer, then the procedure should inform the user
-- of his/her error and prompt for correct data input
--
PROCEDURE T IS
My_Number : Integer;
Well_Formed_Number : Boolean;
BEGIN
Ada_Io.Put("Please enter a number between 1 and 10 ");
LOOP
BEGIN
Ada_Io.Put("=> ");
Ada_Io.Get(My_Number);
--
-- ***** Problem Area ****
--
-- if a keyboard character(s) is entered, i.e. "t" or "test"
-- the Exception Handler catches the Data_Error, then
-- the program will loop back up to the above two statements;
-- however, while the Put statement is correctly executed
-- the Get statment does not permitted any data entry and
-- the program endlessly loops. (An examination of the
-- assembly listing shows that the .asm file produced loops
-- back to the correct position; however, I have not
-- used an assembler to see if the expected action
-- actually occurs).
--
-- Thus, what is displayed after a character i.e. "t" is
-- entered is:
-- An error occurred
-- That is not a number
-- Please re-enter => An error occurred
-- That is not a number
-- Please re-enter => An error occurred
-- That is not a number
-- ...
--
-- the same situation occurs with Ada_Io and the Meridian
-- pre-defined library package Iio which consists of an
-- instantiation of Text_Io.Integer_Io for the standard
-- type integer
--
-- On page 635 of Cohen's book he states "As soon as
-- an unexpected character or terminator is encountered,
-- Get raises Data_Error, and no further characters are
-- read. The offending character or terminator remains
-- unread and can be processed by a subsequent input
-- operation if Data_Error is handled
--
-- Note that if you enter a number such as "888888888"
-- then the program loops as expected (in that it allows
-- a further entry of data in the Get statement)
-- after outputting the following error messages:
--
-- An error occurred
-- That is not a number
--
Well_Formed_Number := True;
EXCEPTION
WHEN Data_Error =>
Well_Formed_Number := False;
Ada_Io.Put_Line("An error occurred");
WHEN OTHERS =>
Ada_Io.Put_Line("Program Abnormally Terminated");
END;
EXIT WHEN Well_Formed_Number AND THEN My_Number IN 1 .. 10;
IF Well_Formed_Number THEN
Ada_Io.Put_Line("That is not between 1 and 10.");
ELSE
Ada_Io.Put_Line("That is not a number.");
END IF;
Ada_Io.Put("Please re-enter");
DELAY (1.0); -- for illustration purposes only
END LOOP;
END T;
next prev parent reply other threads:[~1997-05-29 0:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
1997-05-29 0:00 Help with ADT Stack Jon Elbery
1997-05-29 0:00 ` Michael F Brenner
1997-05-29 0:00 ` David H. Haley [this message]
1997-05-30 0:00 ` Help With Ada_Io and Exceptions John G. Volan
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox