Hazelcast C++ Client
ProtocolExceptions.h
1 /*
2  * Copyright (c) 2008-2018, 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) \
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) {\
42  }\
43  ClassName(const std::string& source, const std::string& message, int32_t causeCode) \
44  : IException(#ClassName, source, message, ERROR_CODE, causeCode) {\
45  }\
46  ClassName(const std::string& source, const std::string& message) \
47  : IException(#ClassName, source, message, ERROR_CODE) {\
48  }\
49  ClassName(const std::string& source) : IException(#ClassName, source, "", ERROR_CODE) {\
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) {}\
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())) {}\
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  DEFINE_EXCEPTION_CLASS(ArrayIndexOutOfBoundsException, protocol::INDEX_OUT_OF_BOUNDS);
63  DEFINE_EXCEPTION_CLASS(ArrayStoreException, protocol::ARRAY_STORE);
64  DEFINE_EXCEPTION_CLASS(AuthenticationException, protocol::AUTHENTICATIONERROR);
65  DEFINE_EXCEPTION_CLASS(CacheNotExistsException, protocol::CACHE_NOT_EXISTS);
66  DEFINE_EXCEPTION_CLASS(CancellationException, protocol::CANCELLATION);
67  DEFINE_EXCEPTION_CLASS(ClassCastException, protocol::CLASS_CAST);
68  DEFINE_EXCEPTION_CLASS(ClassNotFoundException, protocol::CLASS_NOT_FOUND);
69  DEFINE_EXCEPTION_CLASS(ConcurrentModificationException, protocol::CONCURRENT_MODIFICATION);
70  DEFINE_EXCEPTION_CLASS(ConfigMismatchException, protocol::CONFIG_MISMATCH);
71  DEFINE_EXCEPTION_CLASS(ConfigurationException, protocol::CONFIGURATION);
72  DEFINE_EXCEPTION_CLASS(DistributedObjectDestroyedException, protocol::DISTRIBUTED_OBJECT_DESTROYED);
73  DEFINE_EXCEPTION_CLASS(DuplicateInstanceNameException, protocol::DUPLICATE_INSTANCE_NAME);
74  DEFINE_EXCEPTION_CLASS(EOFException, protocol::ENDOFFILE);
75  DEFINE_EXCEPTION_CLASS(ExecutionException, protocol::EXECUTION);
76  DEFINE_EXCEPTION_CLASS(HazelcastException, protocol::HAZELCAST);
77  DEFINE_EXCEPTION_CLASS(HazelcastInstanceNotActiveException, protocol::HAZELCAST_INSTANCE_NOT_ACTIVE);
78  DEFINE_EXCEPTION_CLASS(HazelcastOverloadException, protocol::HAZELCAST_OVERLOAD);
79  DEFINE_EXCEPTION_CLASS(HazelcastSerializationException, protocol::HAZELCAST_SERIALIZATION);
80  DEFINE_EXCEPTION_CLASS(IOException, protocol::IO);
81  DEFINE_EXCEPTION_CLASS(IllegalArgumentException, protocol::ILLEGAL_ARGUMENT);
82  DEFINE_EXCEPTION_CLASS(IllegalAccessException, protocol::ILLEGAL_ACCESS_EXCEPTION);
83  DEFINE_EXCEPTION_CLASS(IllegalAccessError, protocol::ILLEGAL_ACCESS_ERROR);
84  DEFINE_EXCEPTION_CLASS(IllegalMonitorStateException, protocol::ILLEGAL_MONITOR_STATE);
85  DEFINE_EXCEPTION_CLASS(IllegalStateException, protocol::ILLEGAL_STATE);
86  DEFINE_EXCEPTION_CLASS(IllegalThreadStateException, protocol::ILLEGAL_THREAD_STATE);
87  DEFINE_EXCEPTION_CLASS(IndexOutOfBoundsException, protocol::INDEX_OUT_OF_BOUNDS);
88  DEFINE_EXCEPTION_CLASS(InterruptedException, protocol::INTERRUPTED);
89  DEFINE_EXCEPTION_CLASS(InvalidAddressException, protocol::INVALID_ADDRESS);
90  DEFINE_EXCEPTION_CLASS(InvalidConfigurationException, protocol::INVALID_CONFIGURATION);
91  DEFINE_EXCEPTION_CLASS(NegativeArraySizeException, protocol::NEGATIVE_ARRAY_SIZE);
92  DEFINE_EXCEPTION_CLASS(NoSuchElementException, protocol::NO_SUCH_ELEMENT);
93  DEFINE_EXCEPTION_CLASS(NotSerializableException, protocol::NOT_SERIALIZABLE);
94  DEFINE_EXCEPTION_CLASS(NullPointerException, protocol::NULL_POINTER);
95  DEFINE_EXCEPTION_CLASS(OperationTimeoutException, protocol::OPERATION_TIMEOUT);
96  DEFINE_EXCEPTION_CLASS(QueryException, protocol::QUERY);
97  DEFINE_EXCEPTION_CLASS(QueryResultSizeExceededException, protocol::QUERY_RESULT_SIZE_EXCEEDED);
98  DEFINE_EXCEPTION_CLASS(QuorumException, protocol::QUORUM);
99  DEFINE_EXCEPTION_CLASS(ReachedMaxSizeException, protocol::REACHED_MAX_SIZE);
100  DEFINE_EXCEPTION_CLASS(RejectedExecutionException, protocol::REJECTED_EXECUTION);
101  DEFINE_EXCEPTION_CLASS(RemoteMapReduceException, protocol::REMOTE_MAP_REDUCE);
102  DEFINE_EXCEPTION_CLASS(ResponseAlreadySentException, protocol::RESPONSE_ALREADY_SENT);
103  DEFINE_EXCEPTION_CLASS(RuntimeException, protocol::RUNTIME);
104  DEFINE_EXCEPTION_CLASS(SecurityException, protocol::SECURITY);
105  DEFINE_EXCEPTION_CLASS(SocketException, protocol::SOCKET);
109  DEFINE_EXCEPTION_CLASS(StaleSequenceException, protocol::STALE_SEQUENCE);
110  DEFINE_EXCEPTION_CLASS(TargetDisconnectedException, protocol::TARGET_DISCONNECTED);
111  DEFINE_EXCEPTION_CLASS(TimeoutException, protocol::TIMEOUT);
112  DEFINE_EXCEPTION_CLASS(TopicOverloadException, protocol::TOPIC_OVERLOAD);
113  DEFINE_EXCEPTION_CLASS(TransactionException, protocol::TRANSACTION);
114  DEFINE_EXCEPTION_CLASS(TransactionNotActiveException, protocol::TRANSACTION_NOT_ACTIVE);
115  DEFINE_EXCEPTION_CLASS(TransactionTimedOutException, protocol::TRANSACTION_TIMED_OUT);
116  DEFINE_EXCEPTION_CLASS(URISyntaxException, protocol::URI_SYNTAX);
117  DEFINE_EXCEPTION_CLASS(UTFDataFormatException, protocol::UTF_DATA_FORMAT);
118  DEFINE_EXCEPTION_CLASS(UnsupportedOperationException, protocol::UNSUPPORTED_OPERATION);
119  DEFINE_EXCEPTION_CLASS(XAException, protocol::XA);
120  DEFINE_EXCEPTION_CLASS(AccessControlException, protocol::ACCESS_CONTROL);
121  DEFINE_EXCEPTION_CLASS(LoginException, protocol::LOGIN);
122  DEFINE_EXCEPTION_CLASS(UnsupportedCallbackException, protocol::UNSUPPORTED_CALLBACK);
123  DEFINE_EXCEPTION_CLASS(NoDataMemberInClusterException, protocol::NO_DATA_MEMBER);
124  DEFINE_EXCEPTION_CLASS(ReplicatedMapCantBeCreatedOnLiteMemberException, protocol::REPLICATED_MAP_CANT_BE_CREATED);
125  DEFINE_EXCEPTION_CLASS(MaxMessageSizeExceeded, protocol::MAX_MESSAGE_SIZE_EXCEEDED);
126  DEFINE_EXCEPTION_CLASS(WANReplicationQueueFullException, protocol::WAN_REPLICATION_QUEUE_FULL);
127  DEFINE_EXCEPTION_CLASS(AssertionError, protocol::ASSERTION_ERROR);
128  DEFINE_EXCEPTION_CLASS(OutOfMemoryError, protocol::OUT_OF_MEMORY_ERROR);
129  DEFINE_EXCEPTION_CLASS(StackOverflowError, protocol::STACK_OVERFLOW_ERROR);
130  DEFINE_EXCEPTION_CLASS(NativeOutOfMemoryError, protocol::NATIVE_OUT_OF_MEMORY_ERROR);
131  DEFINE_EXCEPTION_CLASS(ServiceNotFoundException, protocol::SERVICE_NOT_FOUND);
132 
133  // ----------------- ONLY Client side exceptions below -------------------------------------------
134  DEFINE_EXCEPTION_CLASS(HazelcastClientNotActiveException, protocol::HAZELCAST_INSTANCE_NOT_ACTIVE);
138  DEFINE_EXCEPTION_CLASS(HazelcastClientOfflineException, protocol::HAZELCAST_CLIENT_OFFLINE);
139  DEFINE_EXCEPTION_CLASS(UnknownHostException, protocol::UNKNOWN_HOST);
140  DEFINE_EXCEPTION_CLASS(FutureUninitialized, protocol::FUTURE_UNINITIALIZED);
141  DEFINE_EXCEPTION_CLASS(ConsistencyLostException, protocol::CONSISTENCY_LOST);
142 
143  class HAZELCAST_API RetryableHazelcastException : public HazelcastException {
144  public:
145  RetryableHazelcastException(const std::string &source, const std::string &message,
146  const std::string &details, int32_t causeCode);
147 
148  RetryableHazelcastException(const std::string &source, const std::string &message, int32_t causeCode);
149 
150  RetryableHazelcastException(const std::string &source, const std::string &message);
151 
152  RetryableHazelcastException(const std::string &source, const std::string &message,
153  const boost::shared_ptr<IException> &cause);
154  };
155 
156 #define DEFINE_RETRYABLE_EXCEPTION_CLASS(ClassName, errorNo) \
157  class HAZELCAST_API ClassName : public RetryableHazelcastException {\
158  public:\
159  static const int32_t ERROR_CODE = errorNo;\
160  ClassName(const std::string& source, const std::string& message, const std::string& details, \
161  int32_t causeCode) \
162  : IException(#ClassName, source, message, details, ERROR_CODE, causeCode), RetryableHazelcastException(source, message, details, causeCode) {\
163  }\
164  ClassName(const std::string& source, const std::string& message, int32_t causeCode) \
165  : IException(#ClassName, source, message, ERROR_CODE, causeCode), RetryableHazelcastException(source, message, causeCode) {\
166  }\
167  ClassName(const std::string& source, const std::string& message) \
168  : IException(#ClassName, source, message, ERROR_CODE), RetryableHazelcastException(source, message) {\
169  }\
170  ClassName(const std::string &source, const std::string &message, \
171  const boost::shared_ptr<IException> &cause) \
172  : IException(#ClassName, source, message, ERROR_CODE, boost::shared_ptr<IException>(cause->clone())), RetryableHazelcastException(source, message, cause) {}\
173  virtual std::auto_ptr<IException> clone() const {\
174  return std::auto_ptr<IException>(new ClassName(*this));\
175  } \
176  virtual void raise() const { throw *this; } \
177  };\
178 
179 
180  DEFINE_RETRYABLE_EXCEPTION_CLASS(CallerNotMemberException, protocol::CALLER_NOT_MEMBER);
181  DEFINE_RETRYABLE_EXCEPTION_CLASS(TopologyChangedException, protocol::TOPOLOGY_CHANGED);
182  DEFINE_RETRYABLE_EXCEPTION_CLASS(PartitionMigratingException, protocol::PARTITION_MIGRATING);
183  DEFINE_RETRYABLE_EXCEPTION_CLASS(RetryableIOException, protocol::RETRYABLE_IO);
184  DEFINE_RETRYABLE_EXCEPTION_CLASS(TargetNotMemberException, protocol::TARGET_NOT_MEMBER);
185  DEFINE_RETRYABLE_EXCEPTION_CLASS(WrongTargetException, protocol::WRONG_TARGET);
186 
187  class MemberLeftException : public ExecutionException, public RetryableHazelcastException {
188  public:
189  MemberLeftException(const std::string &source, const std::string &message, const std::string &details,
190  int32_t causeCode);
191 
192  MemberLeftException(const std::string &source, const std::string &message, int32_t causeCode);
193 
194  MemberLeftException(const std::string &source, const std::string &message);
195 
196  virtual void raise() const;
197 
198  virtual std::auto_ptr<IException> clone() const;
199 
200  };
201 
202  class HAZELCAST_API UndefinedErrorCodeException : public IException {
203  public:
204  UndefinedErrorCodeException(const std::string &source, const std::string &message,
205  int32_t errorCode, int64_t correlationId,
206  std::string details);
207 
208  virtual ~UndefinedErrorCodeException() throw();
209 
210  int32_t getUndefinedErrorCode() const;
211 
212  int64_t getMessageCallId() const;
213 
214  const std::string &getDetailedErrorMessage() const;
215 
216  virtual std::auto_ptr<IException> clone() const;
217 
218  virtual void raise() const;
219 
220  private:
221  int32_t error;
222  int64_t messageCallId;
223  std::string detailedErrorMessage;
224  };
225  }
226  }
227 }
228 
229 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
230 #pragma warning(pop)
231 #endif
232 
233 #endif //HAZELCAST_CLIENT_EXCEPTION_PROTOCOLEXCEPTIONS_H_
Definition: ProtocolExceptions.h:187
Base class for all exception originated from Hazelcast methods.
Definition: IException.h:53
PN (Positive-Negative) CRDT counter.
Definition: MapEntryView.h:32