exception.h
Go to the documentation of this file.
1 
11 #ifndef __MOZOPC_EXCEPTION__H__
12 #define __MOZOPC_EXCEPTION__H__
13 
14 
15 #include <boost/format.hpp>
16 #include <stdexcept>
17 #include <string>
18 #include <vector>
19 
20 
21 namespace Common
22 {
23 
24 struct ErrorData
25 {
26  unsigned ErrorCode;
27  const char * ErrorMessage;
28 
30  : ErrorCode(0)
31  , ErrorMessage(NULL)
32  {
33  }
34 
35  ErrorData(unsigned code, const char * msg)
36  : ErrorCode(code)
37  , ErrorMessage(msg)
38  {
39  }
40 };
41 
42 class Error : public std::exception
43 {
44 public:
45  Error();
46  explicit Error(unsigned lineNum, const char * fileName, unsigned errorCode, const char * msg);
47  virtual ~Error() throw();
48 
49  unsigned GetLineNum() const;
50  std::string GetFileName() const;
51  unsigned GetCode() const;
52  std::string GetMessage() const;
53  std::string GetFullMessage() const;
54 
55  Error & AddError(const Error & subError);
56 
57 public: // std::exception
58  virtual const char * what() const throw();
59 
60 private:
61  unsigned LineNum;
63  unsigned Code;
66  std::vector<Error> SubErrors;
67 };
68 
69 
71  unsigned lineNum,
72  const char * filename,
73  unsigned errorCode,
74  const char * msg)
75 {
76  return Common::Error(lineNum, filename, errorCode, msg);
77 }
78 
79 template <typename T1>
81  unsigned lineNum,
82  const char * fileName,
83  unsigned errorCode,
84  const char * msg,
85  const T1 & param1)
86 {
87  const std::string & resultMessage = str(boost::format(msg) % param1);
88  return Error(lineNum, fileName, errorCode, resultMessage.c_str());
89 }
90 
91 template <typename T1>
93  unsigned lineNum,
94  const char * fileName,
95  unsigned errorCode,
96  const char * msg,
97  const T1 & param1,
98  const Common::Error & subError)
99 {
100  const std::string & resultMessage = str(boost::format(msg) % param1);
101  Error resultError(lineNum, fileName, errorCode, resultMessage.c_str());
102  resultError.AddError(subError);
103  return resultError;
104 }
105 
106 template <typename T1, typename T2>
108  unsigned lineNum,
109  const char * fileName,
110  unsigned errorCode,
111  const char * msg,
112  const T1 & param1,
113  const T2 & param2)
114 {
115  const std::string & resultMessage = str(boost::format(msg) % param1 % param2);
116  return Error(lineNum, fileName, errorCode, resultMessage.c_str());
117 }
118 
119 
120 template <typename T1, typename T2>
122  unsigned lineNum,
123  const char * fileName,
124  unsigned errorCode,
125  const char * msg,
126  const T1 & param1,
127  const T2 & param2,
128  const Common::Error & subError)
129 {
130  const std::string & resultMessage = str(boost::format(msg) % param1 % param2);
131  Error resultError(lineNum, fileName, errorCode, resultMessage.c_str());
132  resultError.AddError(subError);
133  return resultError;
134 }
135 
136 template <typename T1, typename T2, typename T3>
138  unsigned lineNum,
139  const char * fileName,
140  unsigned errorCode,
141  const char * msg,
142  const T1 & param1,
143  const T2 & param2,
144  const T3 & param3)
145 {
146  const std::string & resultMessage = str(boost::format(msg) % param1 % param2 % param3);
147  return Error(lineNum, fileName, errorCode, resultMessage.c_str());
148 }
149 
150 template <typename T1, typename T2, typename T3>
152  unsigned lineNum,
153  const char * fileName,
154  unsigned errorCode,
155  const char * msg,
156  const T1 & param1,
157  const T2 & param2,
158  const T3 & param3,
159  const Common::Error & subError)
160 {
161  const std::string & resultMessage = str(boost::format(msg) % param1 % param2 % param3);
162  Error resultError(lineNum, fileName, errorCode, resultMessage.c_str());
163  resultError.AddError(subError);
164  return resultError;
165 }
166 
167 template <typename T1, typename T2, typename T3, typename T4>
169  unsigned lineNum,
170  const char * fileName,
171  unsigned errorCode,
172  const char * msg,
173  const T1 & param1,
174  const T2 & param2,
175  const T3 & param3,
176  const T4 & param4)
177 {
178  const std::string & resultMessage = str(boost::format(msg) % param1 % param2 % param3 % param4);
179  return Error(lineNum, fileName, errorCode, resultMessage.c_str());
180 }
181 
182 template <typename T1, typename T2, typename T3, typename T4>
184  unsigned lineNum,
185  const char * fileName,
186  unsigned errorCode,
187  const char * msg,
188  const T1 & param1,
189  const T2 & param2,
190  const T3 & param3,
191  const T4 & param4,
192  const Common::Error & subError)
193 {
194  const std::string & resultMessage = str(boost::format(msg) % param1 % param2 % param3 % param4);
195  Error resultError(lineNum, fileName, errorCode, resultMessage.c_str());
196  resultError.AddError(subError);
197  return resultError;
198 }
199 
200 
201 }
202 
203 #define ERROR_CODE(module_id, code) (module_id << 16 | (code & 8))
204 
205 #define THROW_COMMON_ERROR(code, message) throw ::Common::CreateError(__LINE__, __FILE__, code, message)
206 #define CREATE_COMMON_ERROR(code, message) Common::CreateError(__LINE__, __FILE__, code, message)
207 #define THROW_ERROR(data) throw ::Common::CreateError(__LINE__, __FILE__, data.ErrorCode, data.ErrorMessage)
208 #define CREATE_ERROR(data) ::Common::CreateError(__LINE__, __FILE__, data.ErrorCode, data.ErrorMessage)
209 
211 #define CREATE_ERROR1(data, param1) (::Common::CreateError(__LINE__, __FILE__, data.ErrorCode, data.ErrorMessage, param1))
212 #define THROW_ERROR1(data, param1) throw CREATE_ERROR1(data, param1);
213 
214 #define CREATE_ERROR2(data, param1, param2) ::Common::CreateError(__LINE__, __FILE__, data.ErrorCode, data.ErrorMessage, param1, param2)
215 #define THROW_ERROR2(data, param1, param2) throw CREATE_ERROR2(data, param1, param2)
216 
217 #define CREATE_ERROR3(data, param1, param2, param3) ::Common::CreateError(__LINE__, __FILE__, data.ErrorCode, data.ErrorMessage, param1, param2, param3)
218 #define THROW_ERROR3(data, param1, param2, param3) throw CREATE_ERROR3(data, param1, param2, param3)
219 
220 #define CREATE_ERROR4(data, param1, param2, param3, param4) ::Common::CreateError(__LINE__, __FILE__, data.ErrorCode, data.ErrorMessage, param1, param2, param3, param4)
221 #define THROW_ERROR4(data, param1, param2, param3, param4) throw CREATE_ERROR4(data, param1, param2, param3, param4)
222 
223 
224 #include "errors.h"
225 
226 #define THROW_OS_ERROR(UserMsg) (throw ::Common::CreateError(__LINE__, __FILE__, errno, "%1% %2%.", UserMsg, strerror(errno)))
227 
228 #define BEGIN_TRY_BLOCK try{
229 #define END_TRY_BLOCK(handler)\
230 }\
231 catch (const ::Common::Error& err)\
232 {\
233  return handler(err);\
234 }\
235 catch (const std::exception& exc)\
236 {\
237  return handler(CREATE_ERROR1(StdException, exc.what()));\
238 }
239 
240 #endif // __MOZOPC_EXCEPTION__H__
Addon interface definition GNU LGPL.
std::string Message
Definition: exception.h:64
std::string format(CStringRef format_str, ArgList args)
Definition: format.h:3686
const char * ErrorMessage
Definition: exception.h:27
unsigned LineNum
Definition: exception.h:61
unsigned ErrorCode
Definition: exception.h:26
std::string FullMessage
Definition: exception.h:65
std::string FileName
Definition: exception.h:62
Error & AddError(const Error &subError)
Definition: exception.cpp:53
unsigned Code
Definition: exception.h:63
Error CreateError(unsigned lineNum, const char *filename, unsigned errorCode, const char *msg)
Definition: exception.h:70
ErrorData(unsigned code, const char *msg)
Definition: exception.h:35
std::vector< Error > SubErrors
Definition: exception.h:66


ros_opcua_impl_freeopcua
Author(s): Denis Štogl
autogenerated on Tue Jan 19 2021 03:06:04