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作证