From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: 16 Nov 91 21:45:23 GMT From: cis.ohio-state.edu!zaphod.mps.ohio-state.edu!uwm.edu!ogicse!milton!mfeldm an@ucbvax.Berkeley.EDU (Michael Feldman) Subject: Portable End_Error handling desired Message-ID: <1991Nov16.214523.8324@milton.u.washington.edu> List-Id: Ever in search of the elusive portability will-o'-the-wisp, I ask your help in testing the behavior of this program. The idea is to keep the program alive, whatever the nature of the input. (Yes, I know the best way to do this is read the input line into a string, etc., but don't want to do it this way). The program's behavior is predictable and portable EXCEPT when EOF is entered from the keyboard (ctrl-D on Unix, ctrl-Z on DOS, etc.). Tests on 6 different compilers produce at least 3 different behaviors, including in certain cases an undesired propagation of End_Error out of the exception loop, back to the runtime. Any ideas, Ada fans? Mike PS - the behavior if a float literal, or similar, with digits preceding a non-integer character, is undesirable but portable. I know this. -- cut here for program WITH Text_IO; PROCEDURE ExceptionLoop IS PACKAGE My_Int_IO IS New Text_IO.Integer_IO(Integer); MinVal : CONSTANT Integer := -10; MaxVal : CONSTANT Integer := 10; SUBTYPE SmallInt IS Integer RANGE MinVal .. MaxVal; InputValue: SmallInt; Sum: Integer; BEGIN -- ExceptionLoop Sum := 0; FOR Count IN 1..5 LOOP -- counts the five values we need to read LOOP -- inner loop just to control robust input BEGIN -- block for exception handler Text_IO.Put(Item => "Enter an integer between "); My_Int_IO.Put(Item => SmallInt'First, Width => 0); Text_IO.Put(Item => " and "); My_Int_IO.Put(Item => SmallInt'Last, Width => 0); Text_IO.Put(Item => " > "); My_Int_IO.Get(Item => InputValue); EXIT; -- leave the loop only upon correct input EXCEPTION WHEN Constraint_Error => Text_IO.Put ("Value entered is out of range. Please try again."); Text_IO.New_Line; WHEN Text_IO.End_Error => Text_IO.Put ("We are not done yet. Don't enter EOF!"); Text_IO.New_Line; Text_IO.Skip_Line; WHEN Text_IO.Data_Error => Text_IO.Put ("Value entered not an integer. Please try again."); Text_IO.New_Line; Text_IO.Skip_Line; END; -- block for exception handler END LOOP; -- assert: InputValue is in the range MinN to MaxN Sum := Sum + InputValue; -- add new value into Sum END LOOP; Text_IO.Put (Item => "The sum is "); My_Int_IO. Put (Item => Sum, Width => 1); Text_IO.New_Line; END ExceptionLoop;