-
Notifications
You must be signed in to change notification settings - Fork 34
/
Exceptions.h
310 lines (263 loc) · 8.05 KB
/
Exceptions.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
/*
* Exceptions.h
*
* Created on: Jul 22, 2012
* Author: dzhou
*/
#ifndef EXCEPTIONS_H_
#define EXCEPTIONS_H_
#include <exception>
#include <string>
#include "Types.h"
using std::exception;
using std::string;
class TraceableException : public exception {
public:
void addPath(const string& path);
const string& getPath() const {return path_;}
const string& getLastThrow() const { return lastThrow_;}
void setLastThrow(const string& lastThrow);
protected:
string path_;
string lastThrow_;
};
class IncompatibleTypeException: public TraceableException{
public:
IncompatibleTypeException(DATA_TYPE expected, DATA_TYPE actual);
virtual ~IncompatibleTypeException() throw(){}
virtual const char* what() const throw() { return errMsg_.c_str();}
DATA_TYPE expectedType(){return expected_;}
DATA_TYPE actualType(){return actual_;}
private:
DATA_TYPE expected_;
DATA_TYPE actual_;
string errMsg_;
};
class IllegalArgumentException : public TraceableException{
public:
IllegalArgumentException(const string& functionName, const string& errMsg): functionName_(functionName), errMsg_(errMsg){}
virtual const char* what() const throw(){
return errMsg_.c_str();
}
virtual ~IllegalArgumentException() throw(){}
const string& getFunctionName() const { return functionName_;}
private:
const string functionName_;
const string errMsg_;
};
class RuntimeException: public TraceableException{
public:
RuntimeException(const string& errMsg):errMsg_(errMsg){}
virtual const char* what() const throw(){
return errMsg_.c_str();
}
virtual ~RuntimeException() throw(){}
private:
const string errMsg_;
};
class OperatorRuntimeException: public TraceableException{
public:
OperatorRuntimeException(const string& optr,const string& errMsg): operator_(optr),errMsg_(errMsg){}
virtual const char* what() const throw(){
return errMsg_.c_str();
}
virtual ~OperatorRuntimeException() throw(){}
const string& getOperatorName() const { return operator_;}
private:
const string operator_;
const string errMsg_;
};
class TableRuntimeException: public TraceableException{
public:
TableRuntimeException(const string& errMsg): errMsg_(errMsg){}
virtual const char* what() const throw(){
return errMsg_.c_str();
}
virtual ~TableRuntimeException() throw(){}
private:
const string errMsg_;
};
class MemoryException: public TraceableException{
public:
MemoryException():errMsg_("Out of memory"){}
virtual const char* what() const throw(){
return errMsg_.c_str();
}
virtual ~MemoryException() throw(){}
private:
const string errMsg_;
};
class IOException: public TraceableException{
public:
IOException(const string& errMsg): errMsg_(errMsg), errCode_(OTHERERR){}
IOException(const string& errMsg, IO_ERR errCode): errMsg_(errMsg + ". " + getCodeDescription(errCode)), errCode_(errCode){}
IOException(IO_ERR errCode): errMsg_(getCodeDescription(errCode)), errCode_(errCode){}
virtual const char* what() const throw(){
return errMsg_.c_str();
}
virtual ~IOException() throw(){}
IO_ERR getErrorCode() const {return errCode_;}
private:
string getCodeDescription(IO_ERR errCode) const;
private:
const string errMsg_;
const IO_ERR errCode_;
};
class FileChunkVersionCheckException : public exception{
public:
FileChunkVersionCheckException(const string& errMsg) : errMsg_(errMsg){}
virtual const char* what() const throw(){
return errMsg_.c_str();
}
virtual ~FileChunkVersionCheckException() throw(){}
private:
const string errMsg_;
};
class DataCorruptionException: public exception {
public:
DataCorruptionException(const string& errMsg) : errMsg_("<DataCorruption>" + errMsg){}
virtual const char* what() const throw(){
return errMsg_.c_str();
}
virtual ~DataCorruptionException() throw(){}
private:
const string errMsg_;
};
class NotLeaderException: public exception {
public:
//Electing a leader. Wait for a while to retry.
NotLeaderException() : errMsg_("<NotLeader>"){}
//Use the new leader specified in the input argument. format: <host>:<port>:<alias>, e.g. 192.168.1.10:8801:nodeA
NotLeaderException(const string& newLeader) : errMsg_("<NotLeader>" + newLeader), newLeader_(newLeader){}
const string& getNewLeader() const {return newLeader_;}
virtual const char* what() const throw(){
return errMsg_.c_str();
}
virtual ~NotLeaderException() throw(){}
private:
const string errMsg_;
const string newLeader_;
};
class ChunkInTransactionException: public exception {
public:
ChunkInTransactionException(const string& errMsg) : errMsg_("<ChunkInTransaction>" + errMsg){}
virtual const char* what() const throw(){
return errMsg_.c_str();
}
virtual ~ChunkInTransactionException() throw(){}
private:
const string errMsg_;
};
class ChunkInRecoveryException: public exception {
public:
ChunkInRecoveryException(const string& errMsg) : errMsg_("<ChunkInRecovery>" + errMsg){}
virtual const char* what() const throw(){
return errMsg_.c_str();
}
virtual ~ChunkInRecoveryException() throw(){}
private:
const string errMsg_;
};
class DataNodeNotAvailException : public exception {
public:
DataNodeNotAvailException(const string& errMsg) : errMsg_("<DataNodeNotAvail>" + errMsg){}
virtual const char* what() const throw(){
return errMsg_.c_str();
}
virtual ~DataNodeNotAvailException() throw(){}
private:
const string errMsg_;
};
class ControllerNotAvailException : public exception {
public:
ControllerNotAvailException(const string& errMsg) : errMsg_("<ControllerNotAvail>" + errMsg){}
virtual const char* what() const throw(){
return errMsg_.c_str();
}
virtual ~ControllerNotAvailException() throw(){}
private:
const string errMsg_;
};
class ControllerNotReadyException : public exception {
public:
ControllerNotReadyException() : errMsg_("<ControllerNotReady>"){}
virtual const char* what() const throw(){
return errMsg_.c_str();
}
virtual ~ControllerNotReadyException() throw(){}
private:
const string errMsg_;
};
class MathException: public TraceableException {
public:
MathException(const string& errMsg) : errMsg_(errMsg){}
virtual const char* what() const throw(){
return errMsg_.c_str();
}
virtual ~MathException() throw(){}
private:
const string errMsg_;
};
class DataNodeNotReadyException: public TraceableException{
public:
DataNodeNotReadyException(const string& errMsg) : errMsg_("<DataNodeNotReady>" + errMsg){}
virtual const char* what() const throw(){
return errMsg_.c_str();
}
virtual ~DataNodeNotReadyException() throw(){}
private:
const string errMsg_;
};
class NoPrivilegeException: public TraceableException{
public:
NoPrivilegeException(const string& errMsg, bool notAuthenticated) : errMsg_((notAuthenticated ? "<NotAuthenticated>" : "<NoPrivilege>") + errMsg){}
virtual const char* what() const throw(){
return errMsg_.c_str();
}
virtual ~NoPrivilegeException() throw(){}
private:
const string errMsg_;
};
class UserException: public TraceableException{
public:
UserException(const string exceptionType, const string& msg) : exceptionType_(exceptionType), msg_(msg){}
virtual const char* what() const throw(){
return msg_.c_str();
}
const string& getExceptionType() const { return exceptionType_;}
const string& getMessage() const { return msg_;}
virtual ~UserException() throw(){}
private:
string exceptionType_;
string msg_;
};
class SyntaxException: public exception{
public:
SyntaxException(const string& errMsg): errMsg_(errMsg){}
virtual const char* what() const throw(){
return errMsg_.c_str();
}
virtual ~SyntaxException() throw(){}
private:
const string errMsg_;
};
class TestingException: public exception{
public:
TestingException(const string& caseName,const string& subCaseName): name_(caseName),subName_(subCaseName){
if(subName_.empty())
errMsg_="Testing case "+name_+" failed";
else
errMsg_="Testing case "+name_+"_"+subName_+" failed";
}
virtual const char* what() const throw(){
return errMsg_.c_str();
}
const string& getCaseName() const {return name_;}
const string& getSubCaseName() const {return subName_;}
virtual ~TestingException() throw(){}
private:
const string name_;
const string subName_;
string errMsg_;
};
#endif /* EXCEPTIONS_H_ */