Hazelcast C++ Client
IException.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 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);
57 
58  IException(const std::string &exceptionName, const std::string &source, const std::string &message,
59  int32_t errorNo, int32_t causeCode);
60 
61  IException(const std::string &exceptionName, const std::string &source, const std::string &message,
62  int32_t errorNo);
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);
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  friend std::ostream HAZELCAST_API &operator<<(std::ostream &os, const IException &exception);
98 
99  protected:
100  std::string src;
101  std::string msg;
102  std::string details;
103  std::string report;
104  int32_t errorCode;
105  int32_t causeErrorCode;
106  boost::shared_ptr<IException> cause;
107  };
108 
109  std::ostream HAZELCAST_API &operator<<(std::ostream &os, const IException &exception);
110 
111  template<typename EXCEPTIONCLASS>
113  public:
114  ExceptionBuilder(const std::string &source) : source(source) {}
115 
116  template<typename T>
117  ExceptionBuilder &operator<<(const T &message) {
118  msg << message;
119  return *this;
120  }
121 
126  EXCEPTIONCLASS build() {
127  return EXCEPTIONCLASS(source, msg.str());
128  }
129 
130  boost::shared_ptr<EXCEPTIONCLASS> buildShared() {
131  return boost::shared_ptr<EXCEPTIONCLASS>(new EXCEPTIONCLASS(source, msg.str()));
132  }
133 
134  private:
135  std::string source;
136  std::ostringstream msg;
137  };
138 
139  }
140  }
141 }
142 
143 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
144 #pragma warning(pop)
145 #endif
146 
147 #endif //HAZELCAST_EXCEPTION
Base class for all exception originated from Hazelcast methods.
Definition: IException.h:53
EXCEPTIONCLASS build()
Definition: IException.h:126
PN (Positive-Negative) CRDT counter.
Definition: MapEntryView.h:32