-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack_unwinding.cpp
More file actions
76 lines (64 loc) · 1.08 KB
/
stack_unwinding.cpp
File metadata and controls
76 lines (64 loc) · 1.08 KB
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
75
76
#include <iostream>
#include <string>
using namespace std;
void Last() // called by Third()
{
cout << "Start Last" << endl;
cout << "Last throwing int exception" << endl;
throw -1;
cout << "End Last" << endl;
}
void Third() // called by Second()
{
// Will not be free'ed
string * sThirdStand = new string ("Third Samurai");
cout << "Start Third" << endl;
Last();
cout << *sThirdStand << endl;
cout << "End Third" << endl;
delete sThirdStand;
}
void Second() // called by First()
{
cout << "Start Second" << endl;
try
{
Third();
}
catch(double)
{
cerr << "Second caught double exception" << endl;
}
cout << "End Second" << endl;
}
void First() // called by main()
{
cout << "Start First" << endl;
try
{
Second();
}
catch (int)
{
cerr << "First caught int exception" << endl;
}
catch (double)
{
cerr << "First caught double exception" << endl;
}
cout << "End First" << endl;
}
int main()
{
cout << "Start main" << endl;
try
{
First();
}
catch (int)
{
cerr << "main caught int exception" << endl;
}
cout << "End main" << endl;
return 0;
}