082.另一个异常处理的例子

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

procedure Except3 is
   
   procedure Divide_By_Zero(Count:Integer)is
      Divide_Result:Integer;
   begin
      Put("Count is");
      Put(Count,3);
      Put(" and the answer is ");
      Divide_Result:=25/(Count-4);
      Put(Divide_Result,4);
      New_Line;
   exception
      when Constraint_Error=>Put_Line(" Divide by zero error!");
   end Divide_By_Zero;
   
   
   procedure Raise_An_Error(Count:Integer)is
      My_Own_Error:exception;
      Another_Result:Integer;
   begin
      Put("Count is");
      Put(Count,3);
      Another_Result:=35/(Count-6);--untested divide by zero
      if Count=3 then
         raise My_Own_Error;
      end if;
      Put_Line(" and is a legal value ");
   exception
      when My_Own_Error=>Put_Line(" My own error occured");
   end Raise_An_Error;
   
   
   
begin
   Put_Line("Begin a program here!");
   for Count in 1..7 loop
      Divide_By_Zero(Count);
      Raise_An_Error(Count);
   end loop;
   
   Put_Line(" End of program");   
      
      
exception
      when Constraint_Error=>Put("Constraint error detected at the main program level Program terminated.");
      
end Except3;
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值