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