Hazelcast C++ Client
ProtocolExceptions.h
1 /*
2  * Copyright (c) 2008-2019, 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 // Created by sancar koyunlu on 23/07/14.
18 //
19 #ifndef HAZELCAST_CLIENT_EXCEPTION_PROTOCOLEXCEPTIONS_H_
20 #define HAZELCAST_CLIENT_EXCEPTION_PROTOCOLEXCEPTIONS_H_
21 
22 #include <stdint.h>
23 
24 #include "hazelcast/client/exception/IException.h"
25 #include "hazelcast/client/protocol/ClientProtocolErrorCodes.h"
26 
27 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
28 #pragma warning(push)
29 #pragma warning(disable: 4251) //for dll export
30 #endif
31 
32 namespace hazelcast {
33  namespace client {
34  namespace exception {
35 #define DEFINE_EXCEPTION_CLASS(ClassName, errorNo, runtime) \
36  class HAZELCAST_API ClassName : public virtual IException {\
37  public:\
38  static const int32_t ERROR_CODE = errorNo;\
39  ClassName(const std::string& source, const std::string& message, const std::string& details, \
40  int32_t causeCode) \
41  : IException(#ClassName, source, message, details, ERROR_CODE, causeCode, runtime) {\
42  }\
43  ClassName(const std::string& source, const std::string& message, int32_t causeCode) \
44  : IException(#ClassName, source, message, ERROR_CODE, causeCode, runtime) {\
45  }\
46  ClassName(const std::string& source, const std::string& message) \
47  : IException(#ClassName, source, message, ERROR_CODE, runtime) {\
48  }\
49  ClassName(const std::string& source) : IException(#ClassName, source, "", ERROR_CODE, runtime) {\
50  }\
51  ClassName(const std::string &source, const std::string &message, \
52  const boost::shared_ptr<IException> &cause) \
53  : IException(#ClassName, source, message, ERROR_CODE, cause, runtime) {}\
54  ClassName(const std::string &source, const std::string &message, const IException &cause) \
55  : IException(#ClassName, source, message, ERROR_CODE, boost::shared_ptr<IException>(cause.clone()), runtime) {}\
56  virtual std::auto_ptr<IException> clone() const {\
57  return std::auto_ptr<IException>(new ClassName(*this));\
58  } \
59  virtual void raise() const { throw *this; } \
60  };\
61 
62  // --------- Non-RuntimeException starts here -------------------------------------------/
63  DEFINE_EXCEPTION_CLASS(ExecutionException, protocol::EXECUTION, false);
64  DEFINE_EXCEPTION_CLASS(ClassNotFoundException, protocol::CLASS_NOT_FOUND, false);
65  DEFINE_EXCEPTION_CLASS(EOFException, protocol::ENDOFFILE, false);
66  DEFINE_EXCEPTION_CLASS(IOException, protocol::IO, false);
67  DEFINE_EXCEPTION_CLASS(IllegalAccessException, protocol::ILLEGAL_ACCESS_EXCEPTION, false);
68  DEFINE_EXCEPTION_CLASS(IllegalAccessError, protocol::ILLEGAL_ACCESS_ERROR, false);
69  DEFINE_EXCEPTION_CLASS(InterruptedException, protocol::INTERRUPTED, false);
70  DEFINE_EXCEPTION_CLASS(NotSerializableException, protocol::NOT_SERIALIZABLE, false);
71  DEFINE_EXCEPTION_CLASS(SocketException, protocol::SOCKET, false);
72  DEFINE_EXCEPTION_CLASS(TimeoutException, protocol::TIMEOUT, false);
73  DEFINE_EXCEPTION_CLASS(URISyntaxException, protocol::URI_SYNTAX, false);
74  DEFINE_EXCEPTION_CLASS(UTFDataFormatException, protocol::UTF_DATA_FORMAT, false);
75  DEFINE_EXCEPTION_CLASS(XAException, protocol::XA, false);
76  DEFINE_EXCEPTION_CLASS(LoginException, protocol::LOGIN, false);
77  DEFINE_EXCEPTION_CLASS(UnsupportedCallbackException, protocol::UNSUPPORTED_CALLBACK, false);
78  DEFINE_EXCEPTION_CLASS(AssertionError, protocol::ASSERTION_ERROR, false);
79  DEFINE_EXCEPTION_CLASS(OutOfMemoryError, protocol::OUT_OF_MEMORY_ERROR, false);
80  DEFINE_EXCEPTION_CLASS(StackOverflowError, protocol::STACK_OVERFLOW_ERROR, false);
81  DEFINE_EXCEPTION_CLASS(NativeOutOfMemoryError, protocol::NATIVE_OUT_OF_MEMORY_ERROR, false);
82  // --------- Non-RuntimeException ends here -------------------------------------------/
83 
84  // --------- RuntimeException starts here -------------------------------------------/
85  DEFINE_EXCEPTION_CLASS(ArrayIndexOutOfBoundsException, protocol::INDEX_OUT_OF_BOUNDS, true);
86  DEFINE_EXCEPTION_CLASS(ArrayStoreException, protocol::ARRAY_STORE, true);
87  DEFINE_EXCEPTION_CLASS(AuthenticationException, protocol::AUTHENTICATIONERROR, true);
88  DEFINE_EXCEPTION_CLASS(CacheNotExistsException, protocol::CACHE_NOT_EXISTS, true);
89  DEFINE_EXCEPTION_CLASS(CancellationException, protocol::CANCELLATION, true);
90  DEFINE_EXCEPTION_CLASS(ClassCastException, protocol::CLASS_CAST, true);
91  DEFINE_EXCEPTION_CLASS(ConcurrentModificationException, protocol::CONCURRENT_MODIFICATION, true);
92  DEFINE_EXCEPTION_CLASS(ConfigMismatchException, protocol::CONFIG_MISMATCH, true);
93  DEFINE_EXCEPTION_CLASS(ConfigurationException, protocol::CONFIGURATION, true);
94  DEFINE_EXCEPTION_CLASS(DistributedObjectDestroyedException, protocol::DISTRIBUTED_OBJECT_DESTROYED, true);
95  DEFINE_EXCEPTION_CLASS(DuplicateInstanceNameException, protocol::DUPLICATE_INSTANCE_NAME, true);
96  DEFINE_EXCEPTION_CLASS(HazelcastException, protocol::HAZELCAST, true);
97  DEFINE_EXCEPTION_CLASS(HazelcastInstanceNotActiveException, protocol::HAZELCAST_INSTANCE_NOT_ACTIVE, true);
98  DEFINE_EXCEPTION_CLASS(HazelcastOverloadException, protocol::HAZELCAST_OVERLOAD, true);
99  DEFINE_EXCEPTION_CLASS(HazelcastSerializationException, protocol::HAZELCAST_SERIALIZATION, true);
100  DEFINE_EXCEPTION_CLASS(IllegalArgumentException, protocol::ILLEGAL_ARGUMENT, true);
101  DEFINE_EXCEPTION_CLASS(IllegalMonitorStateException, protocol::ILLEGAL_MONITOR_STATE, true);
102  DEFINE_EXCEPTION_CLASS(IllegalStateException, protocol::ILLEGAL_STATE, true);
103  DEFINE_EXCEPTION_CLASS(IllegalThreadStateException, protocol::ILLEGAL_THREAD_STATE, true);
104  DEFINE_EXCEPTION_CLASS(IndexOutOfBoundsException, protocol::INDEX_OUT_OF_BOUNDS, true);
105  DEFINE_EXCEPTION_CLASS(InvalidAddressException, protocol::INVALID_ADDRESS, true);
106  DEFINE_EXCEPTION_CLASS(InvalidConfigurationException, protocol::INVALID_CONFIGURATION, true);
107  DEFINE_EXCEPTION_CLASS(NegativeArraySizeException, protocol::NEGATIVE_ARRAY_SIZE, true);
108  DEFINE_EXCEPTION_CLASS(NoSuchElementException, protocol::NO_SUCH_ELEMENT, true);
109  DEFINE_EXCEPTION_CLASS(NullPointerException, protocol::NULL_POINTER, true);
110  DEFINE_EXCEPTION_CLASS(OperationTimeoutException, protocol::OPERATION_TIMEOUT, true);
111  DEFINE_EXCEPTION_CLASS(QueryException, protocol::QUERY, true);
112  DEFINE_EXCEPTION_CLASS(QueryResultSizeExceededException, protocol::QUERY_RESULT_SIZE_EXCEEDED, true);
113  DEFINE_EXCEPTION_CLASS(QuorumException, protocol::QUORUM, true);
114  DEFINE_EXCEPTION_CLASS(ReachedMaxSizeException, protocol::REACHED_MAX_SIZE, true);
115  DEFINE_EXCEPTION_CLASS(RejectedExecutionException, protocol::REJECTED_EXECUTION, true);
116  DEFINE_EXCEPTION_CLASS(RemoteMapReduceException, protocol::REMOTE_MAP_REDUCE, true);
117  DEFINE_EXCEPTION_CLASS(ResponseAlreadySentException, protocol::RESPONSE_ALREADY_SENT, true);
118  DEFINE_EXCEPTION_CLASS(RuntimeException, protocol::RUNTIME, true);
119  DEFINE_EXCEPTION_CLASS(SecurityException, protocol::SECURITY, true);
123  DEFINE_EXCEPTION_CLASS(StaleSequenceException, protocol::STALE_SEQUENCE, true);
124  DEFINE_EXCEPTION_CLASS(TargetDisconnectedException, protocol::TARGET_DISCONNECTED, true);
125  DEFINE_EXCEPTION_CLASS(TopicOverloadException, protocol::TOPIC_OVERLOAD, true);
126 
127  DEFINE_EXCEPTION_CLASS(TopologyChangedException, protocol::TOPOLOGY_CHANGED, true);
128  DEFINE_EXCEPTION_CLASS(TransactionException, protocol::TRANSACTION, true);
129  DEFINE_EXCEPTION_CLASS(TransactionNotActiveException, protocol::TRANSACTION_NOT_ACTIVE, true);
130  DEFINE_EXCEPTION_CLASS(TransactionTimedOutException, protocol::TRANSACTION_TIMED_OUT, true);
131  DEFINE_EXCEPTION_CLASS(UnsupportedOperationException, protocol::UNSUPPORTED_OPERATION, true);
132  DEFINE_EXCEPTION_CLASS(AccessControlException, protocol::ACCESS_CONTROL, true);
133  DEFINE_EXCEPTION_CLASS(NoDataMemberInClusterException, protocol::NO_DATA_MEMBER, true);
134  DEFINE_EXCEPTION_CLASS(ReplicatedMapCantBeCreatedOnLiteMemberException, protocol::REPLICATED_MAP_CANT_BE_CREATED, true);
135  DEFINE_EXCEPTION_CLASS(MaxMessageSizeExceeded, protocol::MAX_MESSAGE_SIZE_EXCEEDED, true);
136  DEFINE_EXCEPTION_CLASS(WANReplicationQueueFullException, protocol::WAN_REPLICATION_QUEUE_FULL, true);
137  DEFINE_EXCEPTION_CLASS(ServiceNotFoundException, protocol::SERVICE_NOT_FOUND, true);
138 
139  DEFINE_EXCEPTION_CLASS(StaleTaskIdException, protocol::STALE_TASK_ID, true);
140 
141  DEFINE_EXCEPTION_CLASS(DuplicateTaskException, protocol::DUPLICATE_TASK, true);
142 
143  DEFINE_EXCEPTION_CLASS(StaleTaskException, protocol::STALE_TASK, true);
144 
145  DEFINE_EXCEPTION_CLASS(LocalMemberResetException, protocol::LOCAL_MEMBER_RESET, true);
146 
147  DEFINE_EXCEPTION_CLASS(IndeterminateOperationStateException, protocol::INDETERMINATE_OPERATION_STATE, true);
148 
149  DEFINE_EXCEPTION_CLASS(NodeIdOutOfRangeException, protocol::FLAKE_ID_NODE_ID_OUT_OF_RANGE_EXCEPTION, true);
150 
151  DEFINE_EXCEPTION_CLASS(MutationDisallowedException, protocol::MUTATION_DISALLOWED_EXCEPTION, true);
152 
153  class HAZELCAST_API RetryableHazelcastException : public HazelcastException {
154  public:
155  RetryableHazelcastException(const std::string &source, const std::string &message,
156  const std::string &details, int32_t causeCode);
157 
158  RetryableHazelcastException(const std::string &source, const std::string &message, int32_t causeCode);
159 
160  RetryableHazelcastException(const std::string &source, const std::string &message);
161 
162  RetryableHazelcastException(const std::string &source, const std::string &message,
163  const boost::shared_ptr<IException> &cause);
164  };
165 
166 #define DEFINE_RETRYABLE_EXCEPTION_CLASS(ClassName, errorNo) \
167  class HAZELCAST_API ClassName : public RetryableHazelcastException {\
168  public:\
169  static const int32_t ERROR_CODE = errorNo;\
170  ClassName(const std::string& source, const std::string& message, const std::string& details, \
171  int32_t causeCode) \
172  : IException(#ClassName, source, message, details, ERROR_CODE, causeCode, true, true), RetryableHazelcastException(source, message, details, causeCode) {\
173  }\
174  ClassName(const std::string& source, const std::string& message, int32_t causeCode) \
175  : IException(#ClassName, source, message, ERROR_CODE, causeCode, true, true), RetryableHazelcastException(source, message, causeCode) {\
176  }\
177  ClassName(const std::string& source, const std::string& message) \
178  : IException(#ClassName, source, message, ERROR_CODE, true, true), RetryableHazelcastException(source, message) {\
179  }\
180  ClassName(const std::string &source, const std::string &message, \
181  const boost::shared_ptr<IException> &cause) \
182  : IException(#ClassName, source, message, ERROR_CODE, boost::shared_ptr<IException>(cause->clone()), true, true), RetryableHazelcastException(source, message, cause) {}\
183  virtual std::auto_ptr<IException> clone() const {\
184  return std::auto_ptr<IException>(new ClassName(*this));\
185  } \
186  virtual void raise() const { throw *this; } \
187  };\
188 
189 
190  DEFINE_RETRYABLE_EXCEPTION_CLASS(CallerNotMemberException, protocol::CALLER_NOT_MEMBER);
191  DEFINE_RETRYABLE_EXCEPTION_CLASS(PartitionMigratingException, protocol::PARTITION_MIGRATING);
192  DEFINE_RETRYABLE_EXCEPTION_CLASS(RetryableIOException, protocol::RETRYABLE_IO);
193  DEFINE_RETRYABLE_EXCEPTION_CLASS(TargetNotMemberException, protocol::TARGET_NOT_MEMBER);
194  DEFINE_RETRYABLE_EXCEPTION_CLASS(WrongTargetException, protocol::WRONG_TARGET);
195 
196  DEFINE_RETRYABLE_EXCEPTION_CLASS(TargetNotReplicaException, protocol::TARGET_NOT_REPLICA_EXCEPTION);
197 
198  class MemberLeftException : public ExecutionException, public RetryableHazelcastException {
199  public:
200  MemberLeftException(const std::string &source, const std::string &message, const std::string &details,
201  int32_t causeCode);
202 
203  MemberLeftException(const std::string &source, const std::string &message, int32_t causeCode);
204 
205  MemberLeftException(const std::string &source, const std::string &message);
206 
207  virtual void raise() const;
208 
209  virtual std::auto_ptr<IException> clone() const;
210 
211  };
212 
213  // --------- RuntimeException ends here -------------------------------------------------/
214 
215  // ----------------- ONLY Client side exceptions start here ----------------------------------------
216  // ----------------- Client side runtime exceptions start here --------------------------------
217  DEFINE_EXCEPTION_CLASS(HazelcastClientNotActiveException, protocol::HAZELCAST_INSTANCE_NOT_ACTIVE, true);
218  DEFINE_EXCEPTION_CLASS(HazelcastClientOfflineException, protocol::HAZELCAST_CLIENT_OFFLINE, true);
219  DEFINE_EXCEPTION_CLASS(ConsistencyLostException, protocol::CONSISTENCY_LOST, true);
220 
221  class HAZELCAST_API UndefinedErrorCodeException : public IException {
222  public:
223  UndefinedErrorCodeException(const std::string &source, const std::string &message,
224  int32_t errorCode, int64_t correlationId,
225  std::string details);
226 
227  virtual ~UndefinedErrorCodeException() throw();
228 
229  int32_t getUndefinedErrorCode() const;
230 
231  int64_t getMessageCallId() const;
232 
233  const std::string &getDetailedErrorMessage() const;
234 
235  virtual std::auto_ptr<IException> clone() const;
236 
237  virtual void raise() const;
238 
239  private:
240  int32_t error;
241  int64_t messageCallId;
242  std::string detailedErrorMessage;
243  };
244  // ----------------- Client side runtime exceptions finish here --------------------------------
245 
246  // ----------------- Client side non-runtime exceptions start here -----------------------------
250  DEFINE_EXCEPTION_CLASS(UnknownHostException, protocol::UNKNOWN_HOST, false);
251  DEFINE_EXCEPTION_CLASS(FutureUninitialized, protocol::FUTURE_UNINITIALIZED, false);
252  // ----------------- Client side non-runtime exceptions finish here ----------------------------
253 
254  // ----------------- Client side runtime exceptions ends here --------------------------------
255  }
256  }
257 }
258 
259 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
260 #pragma warning(pop)
261 #endif
262 
263 #endif //HAZELCAST_CLIENT_EXCEPTION_PROTOCOLEXCEPTIONS_H_
Definition: ProtocolExceptions.h:198
Base class for all exception originated from Hazelcast methods.
Definition: IException.h:53
PN (Positive-Negative) CRDT counter.
Definition: MapEntryView.h:32