-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ex05 rewind stack.cpp
74 lines (69 loc) · 988 Bytes
/
Ex05 rewind stack.cpp
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <iostream>
#pragma warning (disable:4996)
using namespace std;
class Ex {
enum {SIZE = 255};
char errMessage[SIZE];
public:
Ex(char* pc = "unknown error\n")
{
strcpy(errMessage, pc);
cout << "Ex ctor\n";
}
void Print() const
{
cout << errMessage << endl;
}
Ex(const Ex & obj)
{
strcpy(errMessage, obj.errMessage);
cout << "copy ctor Ex\n";
}
~Ex()
{
cout << "Ex destructor\n";
}
};
class DEx : public Ex{};
class StackObj {
int no;
public:
StackObj(int i = 0) : no (i)
{
cout << "StackObj "<< no << " ctor\n";
}
~StackObj()
{
cout << "StackObj " << no << " destructor\n";
}
};
void func2() {
StackObj obj2(2);
throw Ex("file not Exists\n");
}
void func1() {
StackObj obj1(1);
func2();
}
int mainRS() {
try{
StackObj obj0;
try
{
func1();
}
catch (Ex & e)
{
e.Print();
cout << "Inner catch\n";
}
/*catch(...) {
cout << "...\n";
}*/
}
catch (Ex e)
{
cout << "Otter catch\n";
}
return 0;
}