Hazelcast C++ Client
Hazelcast C++ Client Library
Loading...
Searching...
No Matches
protocol_exceptions.h
1/*
2 * Copyright (c) 2008-2025, Hazelcast, Inc. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <boost/uuid/nil_generator.hpp>
20
21#include "hazelcast/client/exception/iexception.h"
22#include "hazelcast/client/protocol/ClientProtocolErrorCodes.h"
23
24#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
25#pragma warning(push)
26#pragma warning(disable : 4251) // for dll export
27#endif
28
29namespace hazelcast {
30namespace client {
31namespace spi {
32namespace impl {
33class ClientInvocation;
34}
35} // namespace spi
36namespace exception {
37#define DEFINE_EXCEPTION_CLASS(ClassName, errorNo, isRuntime) \
38 class HAZELCAST_API ClassName : public iexception \
39 { \
40 public: \
41 ClassName(std::string source, \
42 std::string message, \
43 std::string details = "", \
44 std::exception_ptr cause = nullptr, \
45 bool retryable = false) \
46 : ClassName(#ClassName, \
47 errorNo, \
48 std::move(source), \
49 std::move(message), \
50 std::move(details), \
51 std::move(cause), \
52 isRuntime, \
53 retryable) \
54 { \
55 } \
56 explicit ClassName(std::string message) \
57 : ClassName("", std::move(message)) \
58 { \
59 } \
60 ClassName() \
61 : ClassName("", "") \
62 { \
63 } \
64 ClassName(std::string errorName, \
65 int32_t errorCode, \
66 std::string source, \
67 std::string message, \
68 std::string details, \
69 std::exception_ptr cause, \
70 bool runtime, \
71 bool retryable) \
72 : iexception(std::move(errorName), \
73 std::move(source), \
74 std::move(message), \
75 std::move(details), \
76 errorCode, \
77 std::move(cause), \
78 runtime, \
79 retryable) \
80 { \
81 } \
82 };
83
84// --------- Non-runtime starts here
85// -------------------------------------------/
86DEFINE_EXCEPTION_CLASS(undefined_error_code, protocol::UNDEFINED, false);
87
88DEFINE_EXCEPTION_CLASS(execution, protocol::EXECUTION, false);
89
90DEFINE_EXCEPTION_CLASS(class_not_found, protocol::CLASS_NOT_FOUND, false);
91
92DEFINE_EXCEPTION_CLASS(eof, protocol::ENDOFFILE, false);
93
94DEFINE_EXCEPTION_CLASS(io, protocol::IO, false);
95
96DEFINE_EXCEPTION_CLASS(illegal_access,
97 protocol::ILLEGAL_ACCESS_EXCEPTION,
98 false);
99
100DEFINE_EXCEPTION_CLASS(illegal_access_error,
101 protocol::ILLEGAL_ACCESS_ERROR,
102 false);
103
104DEFINE_EXCEPTION_CLASS(interrupted, protocol::INTERRUPTED, false);
105
106DEFINE_EXCEPTION_CLASS(not_serializable, protocol::NOT_SERIALIZABLE, false);
107
108DEFINE_EXCEPTION_CLASS(socket, protocol::SOCK_ERROR, false);
109
110DEFINE_EXCEPTION_CLASS(timeout, protocol::TIMEOUT, false);
111DEFINE_EXCEPTION_CLASS(uri_syntax, protocol::URI_SYNTAX, false);
112DEFINE_EXCEPTION_CLASS(utf_data_format, protocol::UTF_DATA_FORMAT, false);
113DEFINE_EXCEPTION_CLASS(xa, protocol::XA, false);
114DEFINE_EXCEPTION_CLASS(login, protocol::LOGIN, false);
115DEFINE_EXCEPTION_CLASS(unsupported_callback,
116 protocol::UNSUPPORTED_CALLBACK,
117 false);
118DEFINE_EXCEPTION_CLASS(assertion_error, protocol::ASSERTION_ERROR, false);
119DEFINE_EXCEPTION_CLASS(out_of_memory_error,
120 protocol::OUT_OF_MEMORY_ERROR,
121 false);
122DEFINE_EXCEPTION_CLASS(stack_overflow_error,
123 protocol::STACK_OVERFLOW_ERROR,
124 false);
125DEFINE_EXCEPTION_CLASS(native_out_of_memory_error,
126 protocol::NATIVE_OUT_OF_MEMORY_ERROR,
127 false);
128// --------- Non-runtime ends here -------------------------------------------/
129
130// --------- runtime starts here -------------------------------------------/
131DEFINE_EXCEPTION_CLASS(array_index_out_of_bounds,
132 protocol::INDEX_OUT_OF_BOUNDS,
133 true);
134DEFINE_EXCEPTION_CLASS(array_store, protocol::ARRAY_STORE, true);
135DEFINE_EXCEPTION_CLASS(authentication, protocol::AUTHENTICATION, true);
136DEFINE_EXCEPTION_CLASS(cache_not_exists, protocol::CACHE_NOT_EXISTS, true);
137DEFINE_EXCEPTION_CLASS(cancellation, protocol::CANCELLATION, true);
138DEFINE_EXCEPTION_CLASS(class_cast, protocol::CLASS_CAST, true);
139DEFINE_EXCEPTION_CLASS(concurrent_modification,
140 protocol::CONCURRENT_MODIFICATION,
141 true);
142DEFINE_EXCEPTION_CLASS(config_mismatch, protocol::CONFIG_MISMATCH, true);
143DEFINE_EXCEPTION_CLASS(distributed_object_destroyed,
144 protocol::DISTRIBUTED_OBJECT_DESTROYED,
145 true);
146DEFINE_EXCEPTION_CLASS(entry_processor, protocol::ENTRY_PROCESSOR, true);
147DEFINE_EXCEPTION_CLASS(hazelcast_, protocol::HAZELCAST, true);
148DEFINE_EXCEPTION_CLASS(hazelcast_instance_not_active,
149 protocol::HAZELCAST_INSTANCE_NOT_ACTIVE,
150 true);
151DEFINE_EXCEPTION_CLASS(hazelcast_overload, protocol::HAZELCAST_OVERLOAD, true);
152DEFINE_EXCEPTION_CLASS(hazelcast_serialization,
153 protocol::HAZELCAST_SERIALIZATION,
154 true);
155DEFINE_EXCEPTION_CLASS(illegal_argument, protocol::ILLEGAL_ARGUMENT, true);
156DEFINE_EXCEPTION_CLASS(illegal_monitor_state,
157 protocol::ILLEGAL_MONITOR_STATE,
158 true);
159DEFINE_EXCEPTION_CLASS(illegal_state, protocol::ILLEGAL_STATE, true);
160DEFINE_EXCEPTION_CLASS(illegal_thread_state,
161 protocol::ILLEGAL_THREAD_STATE,
162 true);
163DEFINE_EXCEPTION_CLASS(index_out_of_bounds,
164 protocol::INDEX_OUT_OF_BOUNDS,
165 true);
166DEFINE_EXCEPTION_CLASS(invalid_address, protocol::INVALID_ADDRESS, true);
167DEFINE_EXCEPTION_CLASS(invalid_configuration,
168 protocol::INVALID_CONFIGURATION,
169 true);
170DEFINE_EXCEPTION_CLASS(negative_array_size,
171 protocol::NEGATIVE_ARRAY_SIZE,
172 true);
173DEFINE_EXCEPTION_CLASS(no_such_element, protocol::NO_SUCH_ELEMENT, true);
174DEFINE_EXCEPTION_CLASS(null_pointer, protocol::NULL_POINTER, true);
175DEFINE_EXCEPTION_CLASS(operation_timeout, protocol::OPERATION_TIMEOUT, true);
176DEFINE_EXCEPTION_CLASS(query_result_size_exceeded,
177 protocol::QUERY_RESULT_SIZE_EXCEEDED,
178 true);
179DEFINE_EXCEPTION_CLASS(split_brain_protection,
180 protocol::SPLIT_BRAIN_PROTECTION,
181 true);
182DEFINE_EXCEPTION_CLASS(reached_max_size, protocol::REACHED_MAX_SIZE, true);
183DEFINE_EXCEPTION_CLASS(rejected_execution, protocol::REJECTED_EXECUTION, true);
184DEFINE_EXCEPTION_CLASS(response_already_sent,
185 protocol::RESPONSE_ALREADY_SENT,
186 true);
187DEFINE_EXCEPTION_CLASS(runtime, protocol::RUNTIME, true);
188DEFINE_EXCEPTION_CLASS(SecurityException, protocol::SECURITY, true);
193DEFINE_EXCEPTION_CLASS(stale_sequence, protocol::STALE_SEQUENCE, true);
194DEFINE_EXCEPTION_CLASS(target_disconnected,
195 protocol::TARGET_DISCONNECTED,
196 true);
197DEFINE_EXCEPTION_CLASS(topic_overload, protocol::TOPIC_OVERLOAD, true);
198
199DEFINE_EXCEPTION_CLASS(transaction, protocol::TRANSACTION, true);
200DEFINE_EXCEPTION_CLASS(transaction_not_active,
201 protocol::TRANSACTION_NOT_ACTIVE,
202 true);
203DEFINE_EXCEPTION_CLASS(transaction_timed_out,
204 protocol::TRANSACTION_TIMED_OUT,
205 true);
206DEFINE_EXCEPTION_CLASS(unsupported_operation,
207 protocol::UNSUPPORTED_OPERATION,
208 true);
209DEFINE_EXCEPTION_CLASS(access_control, protocol::ACCESS_CONTROL, true);
210DEFINE_EXCEPTION_CLASS(no_data_member_in_cluster,
211 protocol::NO_DATA_MEMBER,
212 true);
213DEFINE_EXCEPTION_CLASS(replicated_map_cant_be_created_on_lite_member,
214 protocol::REPLICATED_MAP_CANT_BE_CREATED,
215 true);
216DEFINE_EXCEPTION_CLASS(max_message_size_exceeded,
217 protocol::MAX_MESSAGE_SIZE_EXCEEDED,
218 true);
219DEFINE_EXCEPTION_CLASS(wan_replication_queue_full,
220 protocol::WAN_REPLICATION_QUEUE_FULL,
221 true);
222DEFINE_EXCEPTION_CLASS(service_not_found, protocol::SERVICE_NOT_FOUND, true);
223
224DEFINE_EXCEPTION_CLASS(stale_task_id, protocol::STALE_TASK_ID, true);
225
226DEFINE_EXCEPTION_CLASS(duplicate_task, protocol::DUPLICATE_TASK, true);
227
228DEFINE_EXCEPTION_CLASS(stale_task, protocol::STALE_TASK, true);
229
230DEFINE_EXCEPTION_CLASS(local_member_reset, protocol::LOCAL_MEMBER_RESET, true);
231
232DEFINE_EXCEPTION_CLASS(indeterminate_operation_state,
233 protocol::INDETERMINATE_OPERATION_STATE,
234 true);
235
236DEFINE_EXCEPTION_CLASS(node_id_out_of_range,
237 protocol::FLAKE_ID_NODE_ID_OUT_OF_RANGE_EXCEPTION,
238 true);
239
240DEFINE_EXCEPTION_CLASS(mutation_disallowed,
241 protocol::MUTATION_DISALLOWED_EXCEPTION,
242 true);
243
244DEFINE_EXCEPTION_CLASS(session_expired,
245 protocol::SESSION_EXPIRED_EXCEPTION,
246 true);
247
248DEFINE_EXCEPTION_CLASS(wait_key_cancelled,
249 protocol::WAIT_KEY_CANCELLED_EXCEPTION,
250 true);
251
252DEFINE_EXCEPTION_CLASS(lock_acquire_limit_reached,
253 protocol::LOCK_ACQUIRE_LIMIT_REACHED_EXCEPTION,
254 true);
255
256DEFINE_EXCEPTION_CLASS(lock_ownership_lost,
257 protocol::LOCK_OWNERSHIP_LOST_EXCEPTION,
258 true);
259
260DEFINE_EXCEPTION_CLASS(cp_group_destroyed,
261 protocol::CP_GROUP_DESTROYED_EXCEPTION,
262 true);
263
264DEFINE_EXCEPTION_CLASS(cannot_replicate,
265 protocol::CANNOT_REPLICATE_EXCEPTION,
266 true);
267
268DEFINE_EXCEPTION_CLASS(leader_demoted,
269 protocol::LEADER_DEMOTED_EXCEPTION,
270 true);
271
272DEFINE_EXCEPTION_CLASS(stale_append_request,
273 protocol::STALE_APPEND_REQUEST_EXCEPTION,
274 true);
275
276DEFINE_EXCEPTION_CLASS(not_leader, protocol::NOT_LEADER_EXCEPTION, true);
277
278DEFINE_EXCEPTION_CLASS(version_mismatch,
279 protocol::VERSION_MISMATCH_EXCEPTION,
280 true);
281
282class HAZELCAST_API retryable_hazelcast : public hazelcast_
283{
284public:
285 retryable_hazelcast(std::string error_name,
286 int32_t error_code,
287 std::string source,
288 std::string message,
289 std::string details,
290 std::exception_ptr cause,
291 bool runtime,
292 bool retryable);
293
294 explicit retryable_hazelcast(std::string source = "",
295 std::string message = "",
296 std::string details = "",
297 std::exception_ptr cause = nullptr);
298};
299
300#define DEFINE_RETRYABLE_EXCEPTION_CLASS(ClassName, errorNo) \
301 class HAZELCAST_API ClassName : public retryable_hazelcast \
302 { \
303 public: \
304 explicit ClassName(std::string source = "", \
305 std::string message = "", \
306 std::string details = "", \
307 std::exception_ptr cause = nullptr) \
308 : retryable_hazelcast(#ClassName, \
309 errorNo, \
310 std::move(source), \
311 std::move(message), \
312 std::move(details), \
313 std::move(cause), \
314 false, \
315 true) \
316 { \
317 } \
318 };
319
321DEFINE_RETRYABLE_EXCEPTION_CLASS(caller_not_member,
322 protocol::CALLER_NOT_MEMBER);
323DEFINE_RETRYABLE_EXCEPTION_CLASS(partition_migrating,
324 protocol::PARTITION_MIGRATING);
325DEFINE_RETRYABLE_EXCEPTION_CLASS(retryable_io, protocol::RETRYABLE_IO);
326DEFINE_RETRYABLE_EXCEPTION_CLASS(target_not_member,
327 protocol::TARGET_NOT_MEMBER);
328DEFINE_RETRYABLE_EXCEPTION_CLASS(wrong_target, protocol::WRONG_TARGET);
329
330DEFINE_RETRYABLE_EXCEPTION_CLASS(target_not_replica,
331 protocol::TARGET_NOT_REPLICA_EXCEPTION);
332
333class HAZELCAST_API query : public hazelcast_
334{
335public:
336 explicit query(std::string source = "",
337 std::string message = "",
338 std::string details = "",
339 std::exception_ptr cause = nullptr);
340
341 query(int32_t code,
342 std::string message,
343 std::exception_ptr cause = nullptr,
344 boost::uuids::uuid originating_member_id = boost::uuids::nil_uuid(),
345 std::string suggestion = "");
346
347 int32_t code() const;
348
349 const std::string& suggestion() const;
350
351 const boost::uuids::uuid& originating_member_uuid() const;
352
353private:
354 int32_t code_;
355 std::string suggestion_;
356 boost::uuids::uuid originating_member_uuid_;
357};
358
359class HAZELCAST_API invocation_might_contain_compact_data : public hazelcast_
360{
361public:
362 explicit invocation_might_contain_compact_data(
363 std::string source,
364 const spi::impl::ClientInvocation& invocation);
365};
366
367class HAZELCAST_API member_left : public execution
368{
369public:
370 explicit member_left(std::string source = "",
371 std::string message = "",
372 std::string details = "",
373 std::exception_ptr cause = nullptr);
374};
375
376// --------- runtime ends here
377// -------------------------------------------------/
378
379// ----------------- ONLY Client side exceptions start here
380// ----------------------------------------
381// ----------------- Client side runtime exceptions start here
382// --------------------------------
383class HAZELCAST_API consistency_lost : public hazelcast_
384{
385public:
386 explicit consistency_lost(std::string source = "",
387 std::string message = "",
388 std::string details = "",
389 std::exception_ptr cause = nullptr);
390};
391
392DEFINE_EXCEPTION_CLASS(hazelcast_client_not_active,
393 protocol::HAZELCAST_INSTANCE_NOT_ACTIVE,
394 true);
395
396DEFINE_EXCEPTION_CLASS(hazelcast_client_offline,
397 protocol::HAZELCAST_CLIENT_OFFLINE,
398 true);
399
400// ----------------- Client side runtime exceptions finish here
401// --------------------------------
402
403// ----------------- Client side non-runtime exceptions start here
404// -----------------------------
408DEFINE_EXCEPTION_CLASS(unknown_host, protocol::UNKNOWN_HOST, false);
409
410DEFINE_EXCEPTION_CLASS(client_not_allowed_in_cluster,
411 protocol::CLIENT_NOT_ALLOWED_IN_CLUSTER,
412 true);
413// ----------------- Client side non-runtime exceptions finish here
414// ----------------------------
415
416// ----------------- Client side runtime exceptions ends here
417// --------------------------------
418} // namespace exception
419} // namespace client
420} // namespace hazelcast
421
422#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
423#pragma warning(pop)
424#endif