Remote Call Framework 3.4
Exception.hpp
1 
2 //******************************************************************************
3 // RCF - Remote Call Framework
4 //
5 // Copyright (c) 2005 - 2023, 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.4
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  template<typename T1, typename T2, typename T3, typename T4>
108  Exception(
109  const ErrorMsg& msg,
110  const T1& arg1,
111  const T2& arg2,
112  const T3& arg3,
113  const T4& arg4)
114  {
115  init(msg, convertToString(arg1), convertToString(arg2), convertToString(arg3), convertToString(arg4));
116  }
117 
118  void init(
119  const ErrorMsg& msg,
120  const std::string & arg1 = "",
121  const std::string & arg2 = "",
122  const std::string & arg3 = "",
123  const std::string & arg4 = "");
124 
125 
126  ~Exception() throw();
127 
129  virtual std::unique_ptr<Exception> clone() const;
130 
132  bool good() const;
133 
135  bool bad() const;
136 
138  void clear();
139 
141  const char * what() const throw();
142 
144  int getErrorId() const;
145 
147  std::string getErrorMessage() const;
148 
149  bool getShouldRetry() const;
150  void setShouldRetry(bool shouldRetry);
151 
152  virtual void throwSelf() const;
153 
154  // Deprecated.
155  std::string getErrorString() const;
156 
157  // protected to make serialization of RemoteException simpler
158  protected:
159 
160  int mErrorId = 0;
161  std::string mErrorString;
162  bool mShouldRetry = false;
163  };
164 
165  typedef std::shared_ptr<Exception> ExceptionPtr;
166 
168  class RCF_EXPORT RemoteException : public Exception
169  {
170  public:
171 
172  RemoteException();
173  RemoteException(const Exception& e);
174  RemoteException(const std::string & errorMsg);
175 
177  const ErrorMsg& msg,
178  const std::string & arg1 = "",
179  const std::string & arg2 = "",
180  const std::string & arg3 = "");
181 
182  ~RemoteException() throw();
183 
184 #if RCF_FEATURE_SF==1
185 
186  void serialize(SF::Archive & ar);
187 
188 #endif
189 
190 #if RCF_FEATURE_BOOST_SERIALIZATION==1
191  template<typename Archive>
192  void serialize(Archive &ar, const unsigned int)
193  {
194  ar
195  & mErrorId
196  & mErrorString;
197  }
198 #endif
199 
200  std::unique_ptr<Exception> clone() const;
201 
202  void throwSelf() const;
203 
204  private:
205  std::string mRemoteExceptionType;
206  };
207 
209  class RCF_EXPORT VersioningException : public RemoteException
210  {
211  public:
213  std::uint32_t runtimeVersion,
214  std::uint32_t archiveVersion);
215 
216  ~VersioningException() throw();
217 
219  std::uint32_t getRuntimeVersion() const;
220 
222  std::uint32_t getArchiveVersion() const;
223 
224  std::unique_ptr<Exception> clone() const;
225  void throwSelf() const;
226 
227  private:
228  std::uint32_t mRuntimeVersion;
229  std::uint32_t mArchiveVersion;
230  };
231 
232 } // namespace RCF
233 
234 #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:168
Represents a versioning error raised by a server. Allows the server to specify runtime and archive ve...
Definition: Exception.hpp:209
Definition: AmiIoHandler.hpp:23
RCF_EXPORT bool init(RcfConfigT *=nullptr)
Reference-counted initialization of RCF library. May be called multiple times (see deinit())...