Hazelcast C++ Client
IException.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 msk on 3/13/13.
18 
19 #ifndef HAZELCAST_EXCEPTION
20 #define HAZELCAST_EXCEPTION
21 
22 #include <string>
23 #include <sstream>
24 #include <stdexcept>
25 #include <ostream>
26 #include <memory>
27 
28 #include <boost/shared_ptr.hpp>
29 
30 #include "hazelcast/util/HazelcastDll.h"
31 
32 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
33 #pragma warning(push)
34 #pragma warning(disable: 4251) //for dll export
35 #pragma warning(disable: 4275) //for dll export
36 #endif
37 
38 namespace hazelcast {
39  namespace client {
40  namespace exception {
53  class HAZELCAST_API IException : public std::exception {
54  public:
55  IException(const std::string &exceptionName, const std::string &source, const std::string &message,
56  const std::string &details, int32_t errorNo, int32_t causeCode, bool isRuntime, bool retryable = false);
57 
58  IException(const std::string &exceptionName, const std::string &source, const std::string &message,
59  int32_t errorNo, int32_t causeCode, bool isRuntime, bool retryable = false);
60 
61  IException(const std::string &exceptionName, const std::string &source, const std::string &message,
62  int32_t errorNo, bool isRuntime, bool retryable = false);
63 
64  IException(const std::string &exceptionName, const std::string &source, const std::string &message,
65  int32_t errorNo, const boost::shared_ptr<IException> &cause, bool isRuntime, bool retryable = false);
66 
67  virtual ~IException() throw();
68 
73  virtual char const *what() const throw();
74 
75  const std::string &getSource() const;
76 
77  const std::string &getMessage() const;
78 
79  virtual void raise() const;
80 
87  virtual std::auto_ptr<IException> clone() const;
88 
89  const std::string &getDetails() const;
90 
91  int32_t getErrorCode() const;
92 
93  int32_t getCauseErrorCode() const;
94 
95  const boost::shared_ptr<IException> &getCause() const;
96 
97  bool isRuntimeException() const;
98 
99  bool isRetryable() const;
100 
101  friend std::ostream HAZELCAST_API &operator<<(std::ostream &os, const IException &exception);
102 
103  protected:
104  std::string src;
105  std::string msg;
106  std::string details;
107  std::string report;
108  int32_t errorCode;
109  int32_t causeErrorCode;
110  boost::shared_ptr<IException> cause;
111  bool runtimeException;
112  bool retryable;
113  };
114 
115  std::ostream HAZELCAST_API &operator<<(std::ostream &os, const IException &exception);
116 
117  template<typename EXCEPTIONCLASS>
119  public:
120  ExceptionBuilder(const std::string &source) : source(source) {}
121 
122  template<typename T>
123  ExceptionBuilder &operator<<(const T &message) {
124  msg << message;
125  return *this;
126  }
127 
132  EXCEPTIONCLASS build() {
133  return EXCEPTIONCLASS(source, msg.str());
134  }
135 
136  boost::shared_ptr<EXCEPTIONCLASS> buildShared() {
137  return boost::shared_ptr<EXCEPTIONCLASS>(new EXCEPTIONCLASS(source, msg.str()));
138  }
139 
140  private:
141  std::string source;
142  std::ostringstream msg;
143  };
144 
145  }
146  }
147 }
148 
149 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
150 #pragma warning(pop)
151 #endif
152 
153 #endif //HAZELCAST_EXCEPTION
Base class for all exception originated from Hazelcast methods.
Definition: IException.h:53
EXCEPTIONCLASS build()
Definition: IException.h:132
PN (Positive-Negative) CRDT counter.
Definition: MapEntryView.h:32