exception1.cpp
532 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
using namespace std;
class myexception{};
class tester
{
string name;
public:
tester(const string& n): name(n)
{
cout<<name<<"()"<<endl;
};
~tester()
{
cout<<"~"<<name<<"()"<<endl;
};
};
void f1()
{
tester f1("f1");
throw myexception();
cout << "Exiting f1"<<endl;
}
void f2()
{
tester f2("f2");
f1();
cout << "Exiting f2"<<endl;
}
int main()
{
tester main("main");
try {
f2();
} catch(myexception&)
{
cout << "myxception caught"<<endl;
}
return 0;
}