Pothos  0.2.1-g9f04573d
The Pothos dataflow programming software suite
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros
Exception.hpp
Go to the documentation of this file.
1 
37 #pragma once
38 #include <Pothos/Config.hpp>
39 #include <stdexcept>
40 #include <string>
41 
47 #define POTHOS_EXCEPTION_TRY try{try
48 
55 #define POTHOS_EXCEPTION_CATCH(catchExpr) \
56  catch(const Pothos::Exception &){throw;}\
57  catch(const Poco::Exception &ex){throw Pothos::Exception(ex.displayText());}\
58  catch(const std::exception &ex){throw Pothos::Exception(ex.what());}\
59  catch(...){throw Pothos::Exception("unknown exception");}\
60  }catch(catchExpr)
61 
62 namespace Pothos {
63 
64 
65 class POTHOS_API Exception: public std::exception
68 {
69 public:
70  Exception(const std::string& msg, int code = 0);
72 
73  Exception(const std::string& msg, const std::string& arg, int code = 0);
75 
76  Exception(const std::string& msg, const Exception& nested, int code = 0);
79 
80  Exception(const Exception& exc);
82 
83  ~Exception() throw();
85 
86  Exception& operator = (const Exception& exc);
88 
89  virtual const char* name() const throw();
91 
92  virtual const char* className() const throw();
94 
95  virtual const char* what() const throw();
99 
100  const Exception* nested() const;
103 
104  const std::string& message() const;
106 
107  int code() const;
109 
110  std::string displayText() const;
113 
114  virtual Exception* clone() const;
119 
120  virtual void rethrow() const;
126 
127 protected:
128  Exception(int code = 0);
130 
131  void message(const std::string& msg);
133 
134  void extendedMessage(const std::string& arg);
136 
137 private:
138  std::string _msg;
139  Exception* _pNested;
140  int _code;
141 };
142 
143 
144 //
145 // inlines
146 //
147 inline const Exception* Exception::nested() const
148 {
149  return _pNested;
150 }
151 
152 
153 inline const std::string& Exception::message() const
154 {
155  return _msg;
156 }
157 
158 
159 inline void Exception::message(const std::string& msg)
160 {
161  _msg = msg;
162 }
163 
164 
165 inline int Exception::code() const
166 {
167  return _code;
168 }
169 
170 
171 //
172 // Macros for quickly declaring and implementing exception classes.
173 // Unfortunately, we cannot use a template here because character
174 // pointers (which we need for specifying the exception name)
175 // are not allowed as template arguments.
176 //
177 #define POTHOS_DECLARE_EXCEPTION_CODE(API, CLS, BASE, CODE) \
178  class API CLS: public BASE \
179  { \
180  public: \
181  CLS(int code = CODE); \
182  CLS(const std::string& msg, int code = CODE); \
183  CLS(const std::string& msg, const std::string& arg, int code = CODE); \
184  CLS(const std::string& msg, const Pothos::Exception& exc, int code = CODE); \
185  CLS(const CLS& exc); \
186  ~CLS() throw(); \
187  CLS& operator = (const CLS& exc); \
188  const char* name() const throw(); \
189  const char* className() const throw(); \
190  Pothos::Exception* clone() const; \
191  void rethrow() const; \
192  };
193 
194 #define POTHOS_DECLARE_EXCEPTION(API, CLS, BASE) \
195  POTHOS_DECLARE_EXCEPTION_CODE(API, CLS, BASE, 0)
196 
197 #define POTHOS_IMPLEMENT_EXCEPTION(CLS, BASE, NAME) \
198  CLS::CLS(int code): BASE(code) \
199  { \
200  } \
201  CLS::CLS(const std::string& msg, int code): BASE(msg, code) \
202  { \
203  } \
204  CLS::CLS(const std::string& msg, const std::string& arg, int code): BASE(msg, arg, code) \
205  { \
206  } \
207  CLS::CLS(const std::string& msg, const Pothos::Exception& exc, int code): BASE(msg, exc, code) \
208  { \
209  } \
210  CLS::CLS(const CLS& exc): BASE(exc) \
211  { \
212  } \
213  CLS::~CLS() throw() \
214  { \
215  } \
216  CLS& CLS::operator = (const CLS& exc) \
217  { \
218  BASE::operator = (exc); \
219  return *this; \
220  } \
221  const char* CLS::name() const throw() \
222  { \
223  return NAME; \
224  } \
225  const char* CLS::className() const throw() \
226  { \
227  return typeid(*this).name(); \
228  } \
229  Pothos::Exception* CLS::clone() const \
230  { \
231  return new CLS(*this); \
232  } \
233  void CLS::rethrow() const \
234  { \
235  throw *this; \
236  }
237 
238 
239 //
240 // Standard exception classes
241 //
254 
256 POTHOS_DECLARE_EXCEPTION(POTHOS_API, NotFoundException, RuntimeException)
257 POTHOS_DECLARE_EXCEPTION(POTHOS_API, ExistsException, RuntimeException)
258 POTHOS_DECLARE_EXCEPTION(POTHOS_API, TimeoutException, RuntimeException)
259 POTHOS_DECLARE_EXCEPTION(POTHOS_API, SystemException, RuntimeException)
261 POTHOS_DECLARE_EXCEPTION(POTHOS_API, LibraryLoadException, RuntimeException)
265 POTHOS_DECLARE_EXCEPTION(POTHOS_API, PoolOverflowException, RuntimeException)
266 POTHOS_DECLARE_EXCEPTION(POTHOS_API, NoPermissionException, RuntimeException)
267 POTHOS_DECLARE_EXCEPTION(POTHOS_API, OutOfMemoryException, RuntimeException)
268 POTHOS_DECLARE_EXCEPTION(POTHOS_API, DataException, RuntimeException)
269 
271 POTHOS_DECLARE_EXCEPTION(POTHOS_API, SyntaxException, DataException)
273 POTHOS_DECLARE_EXCEPTION(POTHOS_API, PathSyntaxException, SyntaxException)
274 POTHOS_DECLARE_EXCEPTION(POTHOS_API, IOException, RuntimeException)
276 POTHOS_DECLARE_EXCEPTION(POTHOS_API, FileException, IOException)
283 POTHOS_DECLARE_EXCEPTION(POTHOS_API, OpenFileException, FileException)
284 POTHOS_DECLARE_EXCEPTION(POTHOS_API, WriteFileException, FileException)
285 POTHOS_DECLARE_EXCEPTION(POTHOS_API, ReadFileException, FileException)
287 
289 POTHOS_DECLARE_EXCEPTION(POTHOS_API, BadCastException, RuntimeException)
290 
291 
292 } // namespace Pothos
Definition: Exception.hpp:286
Definition: Exception.hpp:251
Definition: Exception.hpp:277
POTHOS_DECLARE_EXCEPTION(POTHOS_API, ObjectConvertError, RuntimeException)
Definition: Exception.hpp:253
Definition: Exception.hpp:246
const std::string & message() const
Definition: Exception.hpp:153
Definition: Exception.hpp:282
Definition: Exception.hpp:256
Definition: Exception.hpp:279
#define POTHOS_API
Definition: Config.hpp:41
Definition: Exception.hpp:276
Definition: Exception.hpp:258
Definition: Exception.hpp:270
Definition: Exception.hpp:285
Definition: Exception.hpp:247
Definition: Exception.hpp:267
Definition: Exception.hpp:243
Definition: Exception.hpp:284
Definition: Exception.hpp:275
Definition: Exception.hpp:283
Definition: Exception.hpp:262
Definition: Exception.hpp:245
Definition: Exception.hpp:268
Definition: Exception.hpp:266
Definition: Exception.hpp:248
Definition: Exception.hpp:249
Definition: Exception.hpp:274
const Exception * nested() const
Definition: Exception.hpp:147
Definition: Exception.hpp:278
int code() const
Returns the message text.
Definition: Exception.hpp:165
Definition: Exception.hpp:242
Definition: Exception.hpp:265
Definition: Exception.hpp:244
Definition: Exception.hpp:257
Definition: Exception.hpp:259
Definition: Exception.hpp:281
Definition: Exception.hpp:260
Definition: Exception.hpp:255
Definition: Exception.hpp:261
Definition: Exception.hpp:271
Definition: Exception.hpp:288
Definition: Exception.hpp:280
Definition: Exception.hpp:252
Definition: Exception.hpp:250
Definition: Exception.hpp:65
Definition: Exception.hpp:273
Definition: Exception.hpp:272
Definition: Exception.hpp:264
Definition: Exception.hpp:289
Definition: Exception.hpp:263