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
Date: 16 Nov 91 21:45:23 GMT [thread overview]
Message-ID: <1991Nov16.214523.8324@milton.u.washington.edu> (raw)
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;
next reply other threads:[~1991-11-16 21:45 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
1991-11-16 21:45 cis.ohio-state.edu!zaphod.mps.ohio-state.edu!uwm.edu!ogicse!milton!mfeldm [this message]
-- strict thread matches above, loose matches on Subject: below --
1991-11-20 1:17 Portable End_Error handling desired Michael Feldman
1991-11-20 1:58 Robert I. Eachus
1991-11-22 21:34 Robert I. Eachus
1991-12-12 22:06 Robert I. Eachus
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox