• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
demps_c
博客园    首页    新随笔    联系   管理    订阅  订阅
auto_ptr智能指针

using namespace std;
4 class a{
5 public:
6 a(int i){}
7 };
8
9 class b{
10 public:
11 b(){}
12 };
13 void f1(){
14 auto_ptr<a> p1(new a(1));
15 auto_ptr<b> p2(new b);
16 }

 

 

 

 

class chy{
44 public:
45 chy(){value ++;}
46 void print(){
47 cout << value << endl;
48 if(3 == value){
49 throw *this;
50 }
51 }
52 private:
39 void ff1(){
40 throw a(10);
41 throw b();
42 }
43 class chy{
44 public:
45 chy(){value ++;}
46 void print(){
47 cout << value << endl;
48 if(3 == value){
49 throw *this;
50 }
51 }
52 private:
53 static int value;
54 };
55 int chy::value=0;
56 void ff2(){
57
58 try{
59 for(int i=0;i < 10;i ++){
60 chy chy1;
61 chy1.print();
62 }
63 }catch(chy& chy2){
64 cout << "exception" ;
65 chy2.print();
66 }catch(...){
67 cout << "..." << endl;
68 }
69 }

 

1
2
3
exception3
terminate called after throwing an instance of 'chy'
Aborted

刚刚运行结果,表示catch的异常的确就是throw出的异常,有静态变量value作证

posted on 2013-10-03 10:53  demps_c  阅读(163)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3