forked from VoltDB/voltdb-client-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathException.hpp
More file actions
261 lines (235 loc) · 8.49 KB
/
Copy pathException.hpp
File metadata and controls
261 lines (235 loc) · 8.49 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
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
/* This file is part of VoltDB.
* Copyright (C) 2008-2015 VoltDB Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef VOLTDB_EXCEPTION_HPP_
#define VOLTDB_EXCEPTION_HPP_
#include <exception>
#include <cassert>
#include <cstdio>
#include <boost/throw_exception.hpp>
/*
* Boost requires that throw_exceptions() is defined by the user if
* BOOST_NO_EXCEPTIONS is defined. So define it as a no-op here.
*/
#ifdef BOOST_NO_EXCEPTIONS
inline void boost::throw_exception(std::exception const &e) {}
#endif
namespace voltdb {
/* Code for each type of exception */
const int errOk = 0;
const int errException = 1;
const int errNullPointerException = 2;
const int errInvalidColumnException = 3;
const int errOverflowUnderflowException = 4;
const int errIndexOutOfBoundsException = 5;
const int errNonExpandableBufferException = 6;
const int errUninitializedParamsException = 7;
const int errParamMismatchException = 8;
const int errNoMoreRowsException = 9;
const int errStringToDecimalException = 10;
const int errConnectException = 11;
const int errNoConnectionsException = 12;
const int errLibEventException = 13;
const int errClusterInstanceMismatchException = 14;
const int errColumnMismatchException = 15;
const int errMisplacedClientException = 16;
// out parameter type in case we have to change this again.
typedef int errType;
// helper to determine if err is anything other than errOk
inline bool isOk(const errType outParam) {
return outParam == errOk;
}
// set an outParameter.
inline void setErr(errType& outParam, const int errorCode) {
if (!isOk(outParam)) {
printf("Exception is %d\n", outParam);
throw std::exception();
}
assert(isOk(outParam)); // don't overwrite existing err.
outParam = errorCode;
}
/*
* Base class for all exceptions thrown by the VoltDB client API
*/
class Exception : public std::exception {
public:
virtual ~Exception() throw() {}
virtual const char* what() const throw() {
return "An unknown error occured in the VoltDB client API";
}
};
class NullPointerException : public Exception {
public:
NullPointerException() :
Exception() {}
virtual const char* what() const throw() {
return "Found a null pointer where an address was expected";
}
};
/*
* Thrown when attempting to retrieve a column from a Row using a column
* index that is < 0, > num columns, or when using a getter with an inappropriate data type
*/
class InvalidColumnException : public voltdb::Exception {
public:
InvalidColumnException() :
Exception() {}
virtual const char* what() const throw() {
return "Attempted to retrieve a column with an invalid index or name, or an invalid type for the specified column";
}
};
/*
* Thrown by ByteBuffer when an attempt is made to get or put data beyond the limit or capacity of the ByteBuffer
* Users should never see this error since they don't access ByteBuffers directly. They access them
* through message wrappers like AuthenticationRequest, AuthenticationResponse, InvocationResponse, Table,
* TableIterator, and Row.
*/
class OverflowUnderflowException : public voltdb::Exception {
public:
OverflowUnderflowException() : Exception() {}
virtual const char* what() const throw() {
return "Overflow underflow exception";
}
};
/*
* Thrown by ByteBuffer when an attempt is made to access a value at a specific index or set the position/limit
* to a specific index that is < 0 or > the limit/capacity. This should never be seen by users.
*/
class IndexOutOfBoundsException : public voltdb::Exception {
public:
IndexOutOfBoundsException() : Exception() {}
virtual const char* what() const throw() {
return "Index out of bounds exception";
}
};
/*
* Thrown by ByteBuffer when an attempt is made to expand a buffer that is not expandable. Should
* never be seen by users.
*/
class NonExpandableBufferException : public voltdb::Exception {
public:
NonExpandableBufferException() : Exception() {}
virtual const char* what() const throw() {
return "Attempted to add/expand a nonexpandable buffer";
}
};
/*
* Thrown when an attempt is made to invoke a procedure without initializing all the parameters to the procedure.
* Users may see this exception.
*/
class UninitializedParamsException : public voltdb::Exception {
public:
UninitializedParamsException() : Exception() {}
virtual const char* what() const throw() {
return "Not all parameters were set";
}
};
/*
* Thrown when an attempt is made to add a parameter to a parameter set that is the wrong type for the argument
* or an extra argument. Users may see this exception.
*/
class ParamMismatchException : public voltdb::Exception {
public:
ParamMismatchException() : Exception() {}
virtual const char* what() const throw() {
return "Attempted to set a parameter using the wrong type";
}
};
/*
* Thrown by TableIterator when next() is invoked when there are no more rows to return. Users may see this exceptino.
*/
class NoMoreRowsException : public voltdb::Exception {
public:
NoMoreRowsException() : Exception() {}
virtual const char* what() const throw() {
return "Requests another row when there are no more";
}
};
/*
* Thrown by the Decimal string constructor when an attempt is made to construct a Decimal with
* an invalid string. Users may see this exception.
*/
class StringToDecimalException : public voltdb::Exception {
public:
StringToDecimalException() : Exception() {}
virtual const char* what() const throw() {
return "Parse error constructing decimal from string";
}
};
/*
* Thrown when an application specific error occurs during the connection process.
* e.g. Authentication fails while attempting to connect to a node
*/
class ConnectException : public voltdb::Exception {
public:
ConnectException() : Exception() {}
virtual const char* what() const throw() {
return "An error occured while attempting to create and authenticate a connection to VoltDB";
}
};
/*
* Thrown when an attempt is made to invoke a procedure or run the event loop when
* there are no connections to VoltDB.
*/
class NoConnectionsException : public voltdb::Exception {
public:
NoConnectionsException() : Exception() {}
virtual const char* what() const throw() {
return "Attempted to invoke a procedure while there are no connections";
}
};
/*
* Thrown when libevent returns a failure code. These codes are not specific so it isn't possible
* to tell what happened.
*/
class LibEventException : public voltdb::Exception {
public:
LibEventException() : Exception() {}
virtual const char* what() const throw() {
return "Lib event generated an unexpected error";
}
};
class ClusterInstanceMismatchException : public voltdb::Exception {
public:
ClusterInstanceMismatchException() : Exception() {}
virtual const char* what() const throw() {
return "Attempted to connect a client to two separate VoltDB clusters";
}
};
class ColumnMismatchException : public Exception {
const char * what() const throw() {
return "Attempted to set a column using the wrong type";
}
};
/*
* Thrown when an attempt is made to return a client that does not belong to this thread
* back to connection pool.
*/
class MisplacedClientException : public voltdb::Exception {
public:
MisplacedClientException() : Exception() {}
virtual const char* what() const throw() {
return "Attempted to return a client that does not belong to this thread";
}
};
}
#endif /* VOLTDB_EXCEPTION_HPP_ */