-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSEHTester.cpp
More file actions
86 lines (76 loc) · 1.64 KB
/
SEHTester.cpp
File metadata and controls
86 lines (76 loc) · 1.64 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
77
78
79
80
81
82
83
84
85
86
#include "SEHTester.h"
SEHTester::SEHTester()
{
}
SEHTester::~SEHTester()
{
}
void SEHTester::Test() {
int i; cin >> i;
try {
if (i < 0) throw i;
if (i > 0) throw "hello";
cout << "NO EXCEPTION i = " << i << endl;
}
catch (long l) {
cout << "it is long:" << l << endl;
}
catch (int e) {
cout << "it is integer:" << e << endl;
}
catch (const char* s) {
cout << "it is char array:" << s << endl;
}
cout << "the end of program" << endl;
}
void SEHTester::TestSpecifyExceptionTypes() noexcept {
int i; cin >> i;
try {
if (i < 0) throw i;
if (i > 0) throw "hello";
cout << "NO EXCEPTION i = " << i << endl;
}
catch (long l) {
cout << "it is long:" << l << endl;
}
catch (int e) {
throw;
cout << "it is integer:" << e << endl;
}
catch (const char* s) {
cout << "it is char array:" << s << endl;
}
cout << "the end of program" << endl;
}
class DevidedByZero { };
void SEHTester::TestCustomizedExceptionClass() {
double a, b; cin >> a >> b;
try
{
if (b == 0) throw DevidedByZero();
cout << a / b << endl;
}
catch (DevidedByZero&) {
cout << "Devided by zero" << endl;
}
}
class ThrowExceptionInCtor {
public:
ThrowExceptionInCtor()
{
throw 0;
}
~ThrowExceptionInCtor() {
cout << "In ThrowExceptionInCtor deconstructor" << endl;
}
};
void SEHTester::TestThrowExceptionInCtor() {
try
{
ThrowExceptionInCtor t;
}
catch (int)
{
cout << "Catch int exception" << endl;
}
}