What happend: Exception throws in the .ctor()?

1. If an exception was thrown in a type's .ctor(), then the class's destrutor wouldn't be called.
2. If a exception was catched in a try-catch block, all the well-constructed object will be destructed( destrutor method will be called) before enter the catch section:
try
{
  CFoo a;
  CFoo b;


  throw int();


  CFoo c;
}
catch(int& i)
{
  //----
}
the destrutor of a, b will be called except c.
3. Any created heap objects will be well-deleted before existing the try block even though an exception occurs.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
定义一个CircleException类,其中有求面积的方法,当半径小于0时,抛出一个用户自定义异常。当半径radius的不小于零时,输出圆的面积, 当半径radius的小于零时,输出异常发生信息(异常编号[本例设为:1003]与提示异常的类别信息)。 函数接口定义: '''****************你的代码将嵌入这里*****************''' 裁判测试程序样例: 在这里给出函数被调用进行测试的例子。例如: import math class CircleException(Exception): '''****************你的代码将嵌入这里*****************''' obj = ExceptionDemo() # 功能测试 n = eval(input()) for i in range(n): radius = eval(input()) try: obj.Area(radius) except CircleException as e: print("Exception Happend! id:{} , message:{}".format(e.eid, e.message)) ### 输入样例: 在这里给出一组输入。例如: 分n行输入n+1个数据, 第一行:输入一个正整数n (建立圆对象个数n)。 接下去n行输入半径(任意的整型或实型的数据) ```in 4 2 -1 -0.5 1 输出样例: 在这里给出相应的输出。例如: 当半径radius的不小于零时,输出:Area=value (value代码面积值,保留小数点后两位 ),例如Area=0.00 当半径radius的不小于零时,输出:Exception Happend! id:1003, message:Radius Less Than Zero Area=12.57 Exception Happend! id:1003, message:Radius Less Than Zero Exception Happend! id:1003, message:Radius Less Than Zero Area=3.14
最新发布
05-11

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值