Ada数据异常无限循环

时间:2015-10-14 01:10:45

标签: exception exception-handling infinite-loop ada

当执行我的用户创建的get过程时,在异常块中,我的程序处理我的用户定义的异常,但在发生数据异常时进入无限循环。

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;

这是我得到的输出:

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

(无限重复)

有没有人对此错误有任何建议?感谢

0 个答案:

没有答案