Hazelcast C++ Client
Hazelcast C++ Client Library
iexception.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 #pragma once
17 
18 #include <string>
19 #include <stdexcept>
20 #include <ostream>
21 
22 #include <boost/format.hpp>
23 #include <boost/exception_ptr.hpp>
24 
25 #include "hazelcast/util/export.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 #pragma warning(disable: 4275) //for dll export
31 #endif
32 
33 namespace hazelcast {
34  namespace client {
35  namespace exception {
48  class HAZELCAST_API iexception : public std::exception {
49  public:
50  iexception();
51 
52  // TODO: Remove isRuntime and retryable and use the derived class concept as in Java
53  iexception(const std::string &exception_name, const std::string &source, const std::string &message,
54  const std::string &details, int32_t error_no, std::exception_ptr cause, bool is_runtime,
55  bool retryable);
56 
57  ~iexception() noexcept override;
58 
63  char const *what() const noexcept override;
64 
65  const std::string &get_source() const;
66 
67  const std::string &get_message() const;
68 
69  const std::string &get_details() const;
70 
71  int32_t get_error_code() const;
72 
73  bool is_runtime() const;
74 
75  bool is_retryable() const;
76 
77  friend std::ostream HAZELCAST_API &operator<<(std::ostream &os, const iexception &exception);
78 
79  protected:
80  std::string src_;
81  std::string msg_;
82  std::string details_;
83  int32_t error_code_;
84  std::exception_ptr cause_;
85  bool runtime_exception_;
86  bool retryable_;
87  std::string report_;
88  };
89 
90  std::ostream HAZELCAST_API &operator<<(std::ostream &os, const iexception &exception);
91 
92  template<typename EXCEPTIONCLASS>
94  public:
95  explicit exception_builder(const std::string &source) : source_(source) {}
96 
97  template<typename T>
98  exception_builder &operator<<(const T &message) {
99  msg_ << message;
100  return *this;
101  }
102 
107  boost::exception_detail::clone_impl<EXCEPTIONCLASS> build() {
108  return boost::enable_current_exception(EXCEPTIONCLASS(source_, msg_.str()));
109  }
110  private:
111  std::string source_;
112  std::ostringstream msg_;
113  };
114 
115  }
116  }
117 }
118 
119 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
120 #pragma warning(pop)
121 #endif
122 
123 
boost::exception_detail::clone_impl< EXCEPTIONCLASS > build()
Definition: iexception.h:107
Base class for all exception originated from Hazelcast methods.
Definition: iexception.h:48