085.使用Ada内置的异常库

with Ada.Text_IO, Ada.Integer_Text_IO, Ada.Exceptions;
use Ada.Text_IO, Ada.Integer_Text_IO;

procedure Occur is

   Except_ID : Ada.Exceptions.EXCEPTION_OCCURRENCE;

   procedure Divide_Loop is
      Divide_Result : INTEGER;
   begin

      for Index in 1..8 loop
         Put("Index is");
         Put(Index, 3);
         Put(" and the answer is");
         Divide_Result := 25 / (4 - Index);
         Put(Divide_Result, 3);
         New_Line;
      end loop;

   exception
      when Except_ID: Constraint_Error => 
          Put_Line(" Divide by zero error.");
          New_Line;
          Put_Line("  Exception name:");
          Put_Line(Ada.Exceptions.Exception_Name(Except_ID));
          New_Line;
          Put_Line("  Exception information:");
          Put_Line(Ada.Exceptions.Exception_Information(Except_ID));
          New_Line;

      when Except_ID: Storage_Error =>
          Put_Line(" Storage error detected.");
          Put_Line(Ada.Exceptions.Exception_Information(Except_ID));
          New_Line;

      when Except_ID: others =>
          Put_Line(" Unknown exception detected.");
          Put_Line(Ada.Exceptions.Exception_Information(Except_ID));
          New_Line;

   end Divide_Loop;

begin
   Put_Line("Begin program here.");
   Divide_Loop;
   Put_Line("End of program.");
end Occur;


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值