Hazelcast C++ Client
Hazelcast C++ Client Library
All Classes Functions Variables Enumerations Enumerator Pages
protocol_exceptions.h
1 /*
2  * Copyright (c) 2008-2021, 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 "hazelcast/client/exception/iexception.h"
20 #include "hazelcast/client/protocol/ClientProtocolErrorCodes.h"
21 
22 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
23 #pragma warning(push)
24 #pragma warning(disable: 4251) //for dll export
25 #endif
26 
27 namespace hazelcast {
28  namespace client {
29  namespace exception {
30 #define DEFINE_EXCEPTION_CLASS(ClassName, errorNo, isRuntime) \
31  class HAZELCAST_API ClassName : public iexception {\
32  public:\
33  ClassName(const std::string& source, const std::string& message, \
34  const std::string& details = "", std::exception_ptr cause = nullptr, bool retryable = false) \
35  : ClassName(#ClassName, errorNo, source, message, details, cause, isRuntime, retryable) {}\
36  explicit ClassName(const std::string& message) : ClassName("", message) {}\
37  ClassName() : ClassName("", "") {}\
38  ClassName(const std::string& errorName, int32_t errorCode, const std::string& source, const std::string& message, \
39  const std::string& details, std::exception_ptr cause, bool runtime, bool retryable) \
40  : iexception(errorName, source, message, details, errorCode, cause, runtime, retryable) {}\
41  };\
42 
43  // --------- Non-runtime starts here -------------------------------------------/
44  DEFINE_EXCEPTION_CLASS(undefined_error_code , protocol::UNDEFINED, false);
45 
46  DEFINE_EXCEPTION_CLASS(execution , protocol::EXECUTION, false);
47 
48  DEFINE_EXCEPTION_CLASS(class_not_found , protocol::CLASS_NOT_FOUND, false);
49 
50  DEFINE_EXCEPTION_CLASS(eof , protocol::ENDOFFILE, false);
51 
52  DEFINE_EXCEPTION_CLASS(io , protocol::IO, false);
53 
54  DEFINE_EXCEPTION_CLASS(illegal_access , protocol::ILLEGAL_ACCESS_EXCEPTION, false);
55 
56  DEFINE_EXCEPTION_CLASS(illegal_access_error, protocol::ILLEGAL_ACCESS_ERROR, false);
57 
58  DEFINE_EXCEPTION_CLASS(interrupted , protocol::INTERRUPTED, false);
59 
60  DEFINE_EXCEPTION_CLASS(not_serializable , protocol::NOT_SERIALIZABLE, false);
61 
62  DEFINE_EXCEPTION_CLASS(socket , protocol::SOCK_ERROR, false);
63 
64  DEFINE_EXCEPTION_CLASS(timeout , protocol::TIMEOUT, false);
65  DEFINE_EXCEPTION_CLASS(uri_syntax , protocol::URI_SYNTAX, false);
66  DEFINE_EXCEPTION_CLASS(utf_data_format , protocol::UTF_DATA_FORMAT, false);
67  DEFINE_EXCEPTION_CLASS(xa , protocol::XA, false);
68  DEFINE_EXCEPTION_CLASS(login , protocol::LOGIN, false);
69  DEFINE_EXCEPTION_CLASS(unsupported_callback , protocol::UNSUPPORTED_CALLBACK, false);
70  DEFINE_EXCEPTION_CLASS(assertion_error, protocol::ASSERTION_ERROR, false);
71  DEFINE_EXCEPTION_CLASS(out_of_memory_error, protocol::OUT_OF_MEMORY_ERROR, false);
72  DEFINE_EXCEPTION_CLASS(stack_overflow_error, protocol::STACK_OVERFLOW_ERROR, false);
73  DEFINE_EXCEPTION_CLASS(native_out_of_memory_error, protocol::NATIVE_OUT_OF_MEMORY_ERROR, false);
74  // --------- Non-runtime ends here -------------------------------------------/
75 
76  // --------- runtime starts here -------------------------------------------/
77  DEFINE_EXCEPTION_CLASS(array_index_out_of_bounds , protocol::INDEX_OUT_OF_BOUNDS, true);
78  DEFINE_EXCEPTION_CLASS(array_store , protocol::ARRAY_STORE, true);
79  DEFINE_EXCEPTION_CLASS(authentication , protocol::AUTHENTICATION, true);
80  DEFINE_EXCEPTION_CLASS(cache_not_exists , protocol::CACHE_NOT_EXISTS, true);
81  DEFINE_EXCEPTION_CLASS(cancellation , protocol::CANCELLATION, true);
82  DEFINE_EXCEPTION_CLASS(class_cast , protocol::CLASS_CAST, true);
83  DEFINE_EXCEPTION_CLASS(concurrent_modification , protocol::CONCURRENT_MODIFICATION, true);
84  DEFINE_EXCEPTION_CLASS(config_mismatch , protocol::CONFIG_MISMATCH, true);
85  DEFINE_EXCEPTION_CLASS(distributed_object_destroyed , protocol::DISTRIBUTED_OBJECT_DESTROYED, true);
86  DEFINE_EXCEPTION_CLASS(entry_processor , protocol::ENTRY_PROCESSOR, true);
87  DEFINE_EXCEPTION_CLASS(hazelcast_, protocol::HAZELCAST, true);
88  DEFINE_EXCEPTION_CLASS(hazelcast_instance_not_active , protocol::HAZELCAST_INSTANCE_NOT_ACTIVE, true);
89  DEFINE_EXCEPTION_CLASS(hazelcast_overload , protocol::HAZELCAST_OVERLOAD, true);
90  DEFINE_EXCEPTION_CLASS(hazelcast_serialization , protocol::HAZELCAST_SERIALIZATION, true);
91  DEFINE_EXCEPTION_CLASS(illegal_argument , protocol::ILLEGAL_ARGUMENT, true);
92  DEFINE_EXCEPTION_CLASS(illegal_monitor_state , protocol::ILLEGAL_MONITOR_STATE, true);
93  DEFINE_EXCEPTION_CLASS(illegal_state , protocol::ILLEGAL_STATE, true);
94  DEFINE_EXCEPTION_CLASS(illegal_thread_state , protocol::ILLEGAL_THREAD_STATE, true);
95  DEFINE_EXCEPTION_CLASS(index_out_of_bounds , protocol::INDEX_OUT_OF_BOUNDS, true);
96  DEFINE_EXCEPTION_CLASS(invalid_address , protocol::INVALID_ADDRESS, true);
97  DEFINE_EXCEPTION_CLASS(invalid_configuration , protocol::INVALID_CONFIGURATION, true);
98  DEFINE_EXCEPTION_CLASS(negative_array_size , protocol::NEGATIVE_ARRAY_SIZE, true);
99  DEFINE_EXCEPTION_CLASS(no_such_element , protocol::NO_SUCH_ELEMENT, true);
100  DEFINE_EXCEPTION_CLASS(null_pointer , protocol::NULL_POINTER, true);
101  DEFINE_EXCEPTION_CLASS(operation_timeout , protocol::OPERATION_TIMEOUT, true);
102  DEFINE_EXCEPTION_CLASS(query , protocol::QUERY, true);
103  DEFINE_EXCEPTION_CLASS(query_result_size_exceeded , protocol::QUERY_RESULT_SIZE_EXCEEDED, true);
104  DEFINE_EXCEPTION_CLASS(split_brain_protection , protocol::SPLIT_BRAIN_PROTECTION, true);
105  DEFINE_EXCEPTION_CLASS(reached_max_size , protocol::REACHED_MAX_SIZE, true);
106  DEFINE_EXCEPTION_CLASS(rejected_execution , protocol::REJECTED_EXECUTION, true);
107  DEFINE_EXCEPTION_CLASS(response_already_sent , protocol::RESPONSE_ALREADY_SENT, true);
108  DEFINE_EXCEPTION_CLASS(runtime , protocol::RUNTIME, true);
109  DEFINE_EXCEPTION_CLASS(SecurityException, protocol::SECURITY, true);
113  DEFINE_EXCEPTION_CLASS(stale_sequence , protocol::STALE_SEQUENCE, true);
114  DEFINE_EXCEPTION_CLASS(target_disconnected , protocol::TARGET_DISCONNECTED, true);
115  DEFINE_EXCEPTION_CLASS(topic_overload , protocol::TOPIC_OVERLOAD, true);
116 
117  DEFINE_EXCEPTION_CLASS(transaction , protocol::TRANSACTION, true);
118  DEFINE_EXCEPTION_CLASS(transaction_not_active , protocol::TRANSACTION_NOT_ACTIVE, true);
119  DEFINE_EXCEPTION_CLASS(transaction_timed_out , protocol::TRANSACTION_TIMED_OUT, true);
120  DEFINE_EXCEPTION_CLASS(unsupported_operation , protocol::UNSUPPORTED_OPERATION, true);
121  DEFINE_EXCEPTION_CLASS(access_control , protocol::ACCESS_CONTROL, true);
122  DEFINE_EXCEPTION_CLASS(no_data_member_in_cluster, protocol::NO_DATA_MEMBER, true);
123  DEFINE_EXCEPTION_CLASS(replicated_map_cant_be_created_on_lite_member, protocol::REPLICATED_MAP_CANT_BE_CREATED, true);
124  DEFINE_EXCEPTION_CLASS(max_message_size_exceeded, protocol::MAX_MESSAGE_SIZE_EXCEEDED, true);
125  DEFINE_EXCEPTION_CLASS(wan_replication_queue_full, protocol::WAN_REPLICATION_QUEUE_FULL, true);
126  DEFINE_EXCEPTION_CLASS(service_not_found, protocol::SERVICE_NOT_FOUND, true);
127 
128  DEFINE_EXCEPTION_CLASS(stale_task_id, protocol::STALE_TASK_ID, true);
129 
130  DEFINE_EXCEPTION_CLASS(duplicate_task, protocol::DUPLICATE_TASK, true);
131 
132  DEFINE_EXCEPTION_CLASS(stale_task, protocol::STALE_TASK, true);
133 
134  DEFINE_EXCEPTION_CLASS(local_member_reset, protocol::LOCAL_MEMBER_RESET, true);
135 
136  DEFINE_EXCEPTION_CLASS(indeterminate_operation_state, protocol::INDETERMINATE_OPERATION_STATE, true);
137 
138  DEFINE_EXCEPTION_CLASS(node_id_out_of_range, protocol::FLAKE_ID_NODE_ID_OUT_OF_RANGE_EXCEPTION, true);
139 
140  DEFINE_EXCEPTION_CLASS(mutation_disallowed, protocol::MUTATION_DISALLOWED_EXCEPTION, true);
141 
142  DEFINE_EXCEPTION_CLASS(session_expired, protocol::SESSION_EXPIRED_EXCEPTION, true);
143 
144  DEFINE_EXCEPTION_CLASS(wait_key_cancelled , protocol::WAIT_KEY_CANCELLED_EXCEPTION, true);
145 
146  DEFINE_EXCEPTION_CLASS(lock_acquire_limit_reached, protocol::LOCK_ACQUIRE_LIMIT_REACHED_EXCEPTION, true);
147 
148  DEFINE_EXCEPTION_CLASS(lock_ownership_lost, protocol::LOCK_OWNERSHIP_LOST_EXCEPTION, true);
149 
150  DEFINE_EXCEPTION_CLASS(cp_group_destroyed, protocol::CP_GROUP_DESTROYED_EXCEPTION, true);
151 
152  DEFINE_EXCEPTION_CLASS(cannot_replicate, protocol::CANNOT_REPLICATE_EXCEPTION, true);
153 
154  DEFINE_EXCEPTION_CLASS(leader_demoted, protocol::LEADER_DEMOTED_EXCEPTION, true);
155 
156  DEFINE_EXCEPTION_CLASS(stale_append_request, protocol::STALE_APPEND_REQUEST_EXCEPTION, true);
157 
158  DEFINE_EXCEPTION_CLASS(not_leader, protocol::NOT_LEADER_EXCEPTION, true);
159 
160  DEFINE_EXCEPTION_CLASS(version_mismatch, protocol::VERSION_MISMATCH_EXCEPTION, true);
161 
162  class HAZELCAST_API retryable_hazelcast : public hazelcast_ {
163  public:
164  retryable_hazelcast(const std::string &error_name, int32_t error_code, const std::string &source,
165  const std::string &message, const std::string &details,
166  std::exception_ptr cause, bool runtime,
167  bool retryable);
168 
169  explicit retryable_hazelcast(const std::string &source = "", const std::string &message = "",
170  const std::string &details = "", std::exception_ptr cause = nullptr);
171  };
172 
173 #define DEFINE_RETRYABLE_EXCEPTION_CLASS(ClassName, errorNo) \
174  class HAZELCAST_API ClassName : public retryable_hazelcast {\
175  public:\
176  explicit ClassName(const std::string& source = "", const std::string& message = "", const std::string& details = "", std::exception_ptr cause = nullptr) \
177  : retryable_hazelcast(#ClassName, errorNo, source, message, details, cause, false, true) {} \
178  };\
179 
181  DEFINE_RETRYABLE_EXCEPTION_CLASS(caller_not_member, protocol::CALLER_NOT_MEMBER);
182  DEFINE_RETRYABLE_EXCEPTION_CLASS(partition_migrating, protocol::PARTITION_MIGRATING);
183  DEFINE_RETRYABLE_EXCEPTION_CLASS(retryable_io, protocol::RETRYABLE_IO);
184  DEFINE_RETRYABLE_EXCEPTION_CLASS(target_not_member, protocol::TARGET_NOT_MEMBER);
185  DEFINE_RETRYABLE_EXCEPTION_CLASS(wrong_target, protocol::WRONG_TARGET);
186 
187  DEFINE_RETRYABLE_EXCEPTION_CLASS(target_not_replica, protocol::TARGET_NOT_REPLICA_EXCEPTION);
188 
189  class member_left : public execution {
190  public:
191  explicit member_left(const std::string &source = "", const std::string &message = "",
192  const std::string &details = "", std::exception_ptr cause = nullptr);
193  };
194 
195  // --------- runtime ends here -------------------------------------------------/
196 
197  // ----------------- ONLY Client side exceptions start here ----------------------------------------
198  // ----------------- Client side runtime exceptions start here --------------------------------
199  class consistency_lost : public hazelcast_ {
200  public:
201  explicit consistency_lost(const std::string &source = "", const std::string &message = "",
202  const std::string &details = "", std::exception_ptr cause = nullptr);
203  };
204 
205  DEFINE_EXCEPTION_CLASS(hazelcast_client_not_active, protocol::HAZELCAST_INSTANCE_NOT_ACTIVE, true);
206 
207  DEFINE_EXCEPTION_CLASS(hazelcast_client_offline, protocol::HAZELCAST_CLIENT_OFFLINE, true);
208 
209  // ----------------- Client side runtime exceptions finish here --------------------------------
210 
211  // ----------------- Client side non-runtime exceptions start here -----------------------------
215  DEFINE_EXCEPTION_CLASS(unknown_host, protocol::UNKNOWN_HOST, false);
216 
217  DEFINE_EXCEPTION_CLASS(client_not_allowed_in_cluster, protocol::CLIENT_NOT_ALLOWED_IN_CLUSTER, true);
218  // ----------------- Client side non-runtime exceptions finish here ----------------------------
219 
220  // ----------------- Client side runtime exceptions ends here --------------------------------
221  }
222  }
223 }
224 
225 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
226 #pragma warning(pop)
227 #endif