From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,88b13dd2d29fb385 X-Google-Attributes: gid103376,public From: "David H. Haley" Subject: Help With Ada_Io and Exceptions Date: 1997/05/29 Message-ID: <338E3601.3E7E@onlink.net>#1/1 X-Deja-AN: 244859078 References: <338CEEA4.93867B6D@iinet.net.au> Organization: Ontario Northland--ONLink Reply-To: dhaley@onlink.net Newsgroups: comp.lang.ada Date: 1997-05-29T00:00:00+00:00 List-Id: -- 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;