When executing my user-created get procedure, in the exception block, my program handles my user-defined exceptions fine but goes into an infinite loop when a data exception occurs.
PROCEDURE Get (File: IN Ada.Text_IO.File_Type; Item : OUT Rational) IS
N: Integer;
D: Integer;
Dummy: Character; -- dummy character to hold the "/"
BEGIN -- Get
LOOP
BEGIN
Ada.Integer_Text_IO.Get(File => File, Item => N);
Ada.Text_IO.Get (File => File, Item => Dummy);
Ada.Integer_Text_IO.Get(File => File, Item => D);
Item := N/D;
if Dummy /= '/' then
raise BadFormat;
end if;
EXIT;
EXCEPTION
when ZeroDenominator =>
Ada.Text_IO.Put_Line("No Zeroes in Denominator, Please enter data again.");
when BadFormat =>
Ada.Text_IO.Put_Line("Incorrect Formatting, Correct Format is Numerator/Denominator.");
when ADA.IO_EXCEPTIONS.DATA_ERROR =>
Ada.Text_IO.Put_Line("Data Error Occurred, re-enter data like this: ");
Ada.Text_IO.Put_Line("Numerator/Denominator");
END;
END LOOP;
END Get;
This is the output I get:
Data Error Occurred, re-enter data like this:
Numerator/Denominator
Data Error Occurred, re-enter data like this:
Numerator/Denominator
Data Error Occurred, re-enter data like this:
Numerator/Denominator
Data Error Occurred, re-enter data like this:
Numerator/Denominator
(infinitely repeats)
Does anyone have any advice on this error? thanks