Remote Call Framework 3.3
Exception.hpp
1 
2 //******************************************************************************
3 // RCF - Remote Call Framework
4 //
5 // Copyright (c) 2005 - 2022, Delta V Software. All rights reserved.
6 // https://www.deltavsoft.com
7 //
8 // RCF is distributed under dual licenses - closed source or GPL.
9 // Consult your particular license for conditions of use.
10 //
11 // If you have not purchased a commercial license, you are using RCF under GPL terms.
12 //
13 // Version: 3.3
14 // Contact: support <at> deltavsoft.com
15 //
16 //******************************************************************************
17 
18 #ifndef INCLUDE_RCF_EXCEPTION_HPP
19 #define INCLUDE_RCF_EXCEPTION_HPP
20 
21 #include <memory>
22 #include <stdexcept>
23 #include <string>
24 #include <vector>
25 #include <cstdint>
26 
27 #include <RCF/Export.hpp>
28 #include <RCF/Config.hpp>
29 
30 #include <RCF/ErrorMsg.hpp>
31 #include <RCF/MemStream.hpp>
32 
33 namespace SF {
34  class Archive;
35 }
36 
37 namespace RCF {
38 
39  RCF_EXPORT std::string osError(int err);
40 
41 #ifdef _MSC_VER
42 #pragma warning(push)
43 #pragma warning(disable:4100)
44 #pragma warning(disable:4267)
45 #endif
46 
47 #ifdef __cpp_char8_t
48  std::string convertToString(const std::u8string& t);
49 #endif
50 
51  template<typename T>
52  std::string convertToString(T t)
53  {
54  MemOstream os;
55  os << t;
56  return os.string();
57  }
58 
59 #ifdef _MSC_VER
60 #pragma warning(pop)
61 #endif
62 
63  RCF_EXPORT bool shouldDisconnectOnRemoteError(int errorId);
64  RCF_EXPORT int getRuntimeVersionOfThisRemoteCall();
65 
67  class RCF_EXPORT Exception : public std::exception
68  {
69  public:
70  Exception();
71 
72  Exception(const std::string & errorMsg);
73 
74  Exception(
75  const ErrorMsg& msg,
76  const std::string & arg1 = "",
77  const std::string & arg2 = "",
78  const std::string & arg3 = "");
79 
80  template<typename T1>
81  Exception(
82  const ErrorMsg& msg,
83  const T1& arg1)
84  {
85  init(msg, convertToString(arg1), "", "");
86  }
87 
88  template<typename T1, typename T2>
89  Exception(
90  const ErrorMsg& msg,
91  const T1& arg1,
92  const T2& arg2)
93  {
94  init(msg, convertToString(arg1), convertToString(arg2), "");
95  }
96 
97  template<typename T1, typename T2, typename T3>
98  Exception(
99  const ErrorMsg& msg,
100  const T1& arg1,
101  const T2& arg2,
102  const T3& arg3)
103  {
104  init(msg, convertToString(arg1), convertToString(arg2), convertToString(arg3));
105  }
106 
107  void init(
108  const ErrorMsg& msg,
109  const std::string & arg1 = "",
110  const std::string & arg2 = "",
111  const std::string & arg3 = "");
112 
113 
114  ~Exception() throw();
115 
117  virtual std::unique_ptr<Exception> clone() const;
118 
120  bool good() const;
121 
123  bool bad() const;
124 
126  void clear();
127 
129  const char * what() const throw();
130 
132  int getErrorId() const;
133 
135  std::string getErrorMessage() const;
136 
137  bool getShouldRetry() const;
138  void setShouldRetry(bool shouldRetry);
139 
140  virtual void throwSelf() const;
141 
142  // Deprecated.
143  std::string getErrorString() const;
144 
145  // protected to make serialization of RemoteException simpler
146  protected:
147 
148  int mErrorId = 0;
149  std::string mErrorString;
150  bool mShouldRetry = false;
151  };
152 
153  typedef std::shared_ptr<Exception> ExceptionPtr;
154 
156  class RCF_EXPORT RemoteException : public Exception
157  {
158  public:
159 
160  RemoteException();
161  RemoteException(const Exception& e);
162  RemoteException(const std::string & errorMsg);
163 
165  const ErrorMsg& msg,
166  const std::string & arg1 = "",
167  const std::string & arg2 = "",
168  const std::string & arg3 = "");
169 
170  ~RemoteException() throw();
171 
172 #if RCF_FEATURE_SF==1
173 
174  void serialize(SF::Archive & ar);
175 
176 #endif
177 
178 #if RCF_FEATURE_BOOST_SERIALIZATION==1
179  template<typename Archive>
180  void serialize(Archive &ar, const unsigned int)
181  {
182  ar
183  & mErrorId
184  & mErrorString;
185  }
186 #endif
187 
188  std::unique_ptr<Exception> clone() const;
189 
190  void throwSelf() const;
191 
192  private:
193  std::string mRemoteExceptionType;
194  };
195 
197  class RCF_EXPORT VersioningException : public RemoteException
198  {
199  public:
201  std::uint32_t runtimeVersion,
202  std::uint32_t archiveVersion);
203 
204  ~VersioningException() throw();
205 
207  std::uint32_t getRuntimeVersion() const;
208 
210  std::uint32_t getArchiveVersion() const;
211 
212  std::unique_ptr<Exception> clone() const;
213  void throwSelf() const;
214 
215  private:
216  std::uint32_t mRuntimeVersion;
217  std::uint32_t mArchiveVersion;
218  };
219 
220 } // namespace RCF
221 
222 #endif // ! INCLUDE_RCF_EXCEPTION_HPP
Represents an archive, in which serialized objects are stored.
Definition: Archive.hpp:31
RCF_EXPORT std::uint32_t getArchiveVersion()
Gets the RCF archive version number.
Base class for all RCF exceptions.
Definition: Exception.hpp:67
Definition: ByteBuffer.hpp:188
RCF_EXPORT std::uint32_t getRuntimeVersion()
Gets the RCF runtime version number.
Represents an error that occurs on a RCF server and is transmitted back to the client.
Definition: Exception.hpp:156
Represents a versioning error raised by a server. Allows the server to specify runtime and archive ve...
Definition: Exception.hpp:197
Definition: AmiIoHandler.hpp:23
RCF_EXPORT bool init(RcfConfigT *=nullptr)
Reference-counted initialization of RCF library. May be called multiple times (see deinit())...