-
Notifications
You must be signed in to change notification settings - Fork 0
/
d_except.h
162 lines (141 loc) · 3.09 KB
/
d_except.h
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#ifndef EXCEPTION_CLASSES
#define EXCEPTION_CLASSES
#include <strstream>
#include <string>
using namespace std;
class baseException
{
public:
baseException(const string& str = ""):
msgString(str)
{
if (msgString == "")
msgString = "Unspecified exception";
}
string what() const
{
return msgString;
}
// protected allows a derived class to access msgString.
// chapter 13 discusses protected in detail
protected:
string msgString;
};
// failure to allocate memory (new() returns NULL)
class memoryAllocationError: public baseException
{
public:
memoryAllocationError(const string& msg = ""):
baseException(msg)
{}
};
// function argument out of proper range
class rangeError: public baseException
{
public:
rangeError(const string& msg = ""):
baseException(msg)
{}
};
// index out of range
class indexRangeError: public baseException
{
public:
indexRangeError(const string& msg, int i, int size):
baseException()
{
char indexString[80];
ostrstream indexErr(indexString, 80);
indexErr << msg << " index " << i << " size = " << size << ends;
// indexRangeError can modify msgString, since it is in
// the protected section of baseException
msgString = indexString;
}
};
// attempt to erase from an empty container
class underflowError: public baseException
{
public:
underflowError(const string& msg = ""):
baseException(msg)
{}
};
// attempt to insert into a full container
class overflowError: public baseException
{
public:
overflowError(const string& msg = ""):
baseException(msg)
{}
};
// error in expression evaluation
class expressionError: public baseException
{
public:
expressionError(const string& msg = ""):
baseException(msg)
{}
};
// bad object reference
class referenceError: public baseException
{
public:
referenceError(const string& msg = ""):
baseException(msg)
{}
};
// feature not implemented
class notImplementedError: public baseException
{
public:
notImplementedError(const string& msg = ""):
baseException(msg)
{}
};
// date errors
class dateError: public baseException
{
public:
dateError(const string& first, int v, const string& last):
baseException()
{
char dateStr[80];
ostrstream dateErr(dateStr, 80);
dateErr << first << ' ' << v << ' ' << last << ends;
// dateError can modify msgString, since it is in
// the protected section of baseException
msgString = dateStr;
}
};
// error in graph class
class graphError: public baseException
{
public:
graphError(const string& msg = ""):
baseException(msg)
{}
};
// file open error
class fileOpenError: public baseException
{
public:
fileOpenError(const string& fname):
baseException()
{
char errorStr[80];
ostrstream fileErr(errorStr, 80);
fileErr << "Cannot open \"" << fname << "\"" << ends;
// fileOpenError can modify msgString, since it is in
// the protected section of baseException
msgString = errorStr;
}
};
// error in graph class
class fileError: public baseException
{
public:
fileError(const string& msg = ""):
baseException(msg)
{}
};
#endif // EXCEPTION_CLASSES