OpenLexocad  27.1
Exception.h
Go to the documentation of this file.
1 #ifndef __EXCEPTION_H__
2 #define __EXCEPTION_H__
3 
4 //#include <Base/Base.h>
5 #include <exception>
6 #include <string>
7 
8 /* MACROS FOR THROWING EXCEPTIONS */
9 
19 
20 #ifdef _MSC_VER
21 
22 #define THROW(exception) \
23  { \
24  exception myexcp; \
25  myexcp.setDebugInformation(__FILE__, __LINE__, __FUNCSIG__); \
26  throw myexcp; \
27  }
28 #define THROWM(exception, message) \
29  { \
30  exception myexcp(message); \
31  myexcp.setDebugInformation(__FILE__, __LINE__, __FUNCSIG__); \
32  throw myexcp; \
33  }
34 #define THROWMF_FILEEXCEPTION(message, filenameorfileinfo) \
35  { \
36  FileException myexcp(message, filenameorfileinfo); \
37  myexcp.setDebugInformation(__FILE__, __LINE__, __FUNCSIG__); \
38  throw myexcp; \
39  }
40 
41 #define THROWT(exception) \
42  { \
43  exception myexcp; \
44  myexcp.setDebugInformation(__FILE__, __LINE__, __FUNCSIG__); \
45  myexcp.setTranslatable(true); \
46  throw myexcp; \
47  }
48 #define THROWMT(exception, message) \
49  { \
50  exception myexcp(message); \
51  myexcp.setDebugInformation(__FILE__, __LINE__, __FUNCSIG__); \
52  myexcp.setTranslatable(true); \
53  throw myexcp; \
54  }
55 #define THROWMFT_FILEEXCEPTION(message, filenameorfileinfo) \
56  { \
57  FileException myexcp(message, filenameorfileinfo); \
58  myexcp.setDebugInformation(__FILE__, __LINE__, __FUNCSIG__); \
59  myexcp.setTranslatable(true); \
60  throw myexcp; \
61  }
62 
63 #elif defined(__GNUC__)
64 
65 #define THROW(exception) \
66  { \
67  exception myexcp; \
68  myexcp.setDebugInformation(__FILE__, __LINE__, __PRETTY_FUNCTION__); \
69  throw myexcp; \
70  }
71 #define THROWM(exception, message) \
72  { \
73  exception myexcp(message); \
74  myexcp.setDebugInformation(__FILE__, __LINE__, __PRETTY_FUNCTION__); \
75  throw myexcp; \
76  }
77 #define THROWMF_FILEEXCEPTION(message, filenameorfileinfo) \
78  { \
79  FileException myexcp(message, filenameorfileinfo); \
80  myexcp.setDebugInformation(__FILE__, __LINE__, __PRETTY_FUNCTION__); \
81  throw myexcp; \
82  }
83 
84 #define THROWT(exception) \
85  { \
86  exception myexcp; \
87  myexcp.setDebugInformation(__FILE__, __LINE__, __PRETTY_FUNCTION__); \
88  myexcp.setTranslatable(true); \
89  throw myexcp; \
90  }
91 #define THROWMT(exception, message) \
92  { \
93  exception myexcp(message); \
94  myexcp.setDebugInformation(__FILE__, __LINE__, __PRETTY_FUNCTION__); \
95  myexcp.setTranslatable(true); \
96  throw myexcp; \
97  }
98 #define THROWMFT_FILEEXCEPTION(message, filenameorfileinfo) \
99  { \
100  FileException myexcp(message, filenameorfileinfo); \
101  myexcp.setDebugInformation(__FILE__, __LINE__, __PRETTY_FUNCTION__); \
102  myexcp.setTranslatable(true); \
103  throw myexcp; \
104  }
105 
106 #else
107 
108 #define THROW(exception) \
109  { \
110  exception myexcp; \
111  myexcp.setDebugInformation(__FILE__, __LINE__, __func__); \
112  throw myexcp; \
113  }
114 #define THROWM(exception, message) \
115  { \
116  exception myexcp(message); \
117  myexcp.setDebugInformation(__FILE__, __LINE__, __func__); \
118  throw myexcp; \
119  }
120 #define THROWMF_FILEEXCEPTION(message, filenameorfileinfo) \
121  { \
122  FileException myexcp(message, filenameorfileinfo); \
123  myexcp.setDebugInformation(__FILE__, __LINE__, __func__); \
124  throw myexcp; \
125  }
126 
127 #define THROWT(exception) \
128  { \
129  exception myexcp; \
130  myexcp.setDebugInformation(__FILE__, __LINE__, __func__); \
131  myexcp.setTranslatable(true); \
132  throw myexcp; \
133  }
134 #define THROWMT(exception, message) \
135  { \
136  exception myexcp(message); \
137  myexcp.setDebugInformation(__FILE__, __LINE__, __func__); \
138  myexcp.setTranslatable(true); \
139  throw myexcp; \
140  }
141 #define THROWMFT_FILEEXCEPTION(message, filenameorfileinfo) \
142  { \
143  FileException myexcp(message, filenameorfileinfo); \
144  myexcp.setDebugInformation(__FILE__, __LINE__, __func__); \
145  myexcp.setTranslatable(true); \
146  throw myexcp; \
147  }
148 
149 
150 #endif
151 
152 #define FC_THROWM(_exception, _msg) \
153  do \
154  { \
155  std::stringstream ss; \
156  ss << _msg; \
157  THROWM(_exception, ss.str().c_str()); \
158  } while (0)
159 
160 #define THROW_CON_ERR_IF(_condition_, _msg_) \
161  if (_condition_) \
162  throw Base::ConstructionError(_msg_);
163 
164 #define THROW_FAIL_NDONE_IF(_condition_, _msg_) \
165  if (_condition_) \
166  throw Base::FailedNotDone(_msg_);
167 
168 namespace Base
169 {
170 class LX_BASE_EXPORT Exception
171 {
172 public:
173  Exception(const char* sMessage, const char* detail);
174  Exception(void);
175  Exception(const Exception& inst);
176  virtual ~Exception() throw() {}
177 
178  Exception& operator=(const Exception& inst);
179 
180  virtual const char* what(void) const throw();
181  virtual const char* detail(void) const throw();
182 
183  void ReportException(void) const;
184 
185  inline void SetMessage(const char* sMessage);
186 
187  inline std::string getFile() const;
188  inline int getLine() const;
189  inline std::string getFunction() const;
190  inline bool getTranslatable() const;
191  inline bool getReported() const { return _isReported; }
192 
195  inline void setDebugInformation(const std::string& file, const int line, const std::string& function);
196  inline void setTranslatable(bool translatable);
197  inline void setReported(bool reported) { _isReported = reported; }
198 
199 protected:
200 #ifdef _MSC_VER
201 #pragma warning(disable : 4251)
202 #endif
203  std::string _sErrMsg;
204  std::string _sErrDetail;
205  std::string _file{ "" };
206  int _line{ -1 };
207  std::string _function{ "" };
208  bool _isTranslatable{ false };
209  mutable bool _isReported{ false };
210 };
211 
212 
217 class LX_BASE_EXPORT AbortException : public Exception
218 {
219 public:
221  AbortException(const char* sMessage);
223  AbortException();
225  AbortException(const AbortException& inst);
227  virtual ~AbortException() throw() {}
229  virtual const char* what() const throw();
230 };
231 
236 class LX_BASE_EXPORT MemoryException : public Exception
237 {
238 public:
240  MemoryException();
242  MemoryException(const MemoryException& inst);
244  virtual ~MemoryException() throw() {}
245 };
246 
247 
248 inline void Exception::SetMessage(const char* sMessage)
249 {
250  _sErrMsg = sMessage;
251 }
252 
257 class LX_BASE_EXPORT ConstructionError : public Exception
258 {
259 public:
261  ConstructionError(const char* sMessage);
267  virtual ~ConstructionError() throw() {}
269  virtual const char* what() const throw();
270 };
271 
275 class LX_BASE_EXPORT FailedNotDone : public Exception
276 {
277 public:
279  FailedNotDone(const char* sMessage);
281  FailedNotDone();
283  FailedNotDone(const FailedNotDone& inst);
285  virtual ~FailedNotDone() throw() {}
287  virtual const char* what() const throw();
288 };
289 
293 class LX_BASE_EXPORT ItemNotFound : public Exception
294 {
295 public:
297  ItemNotFound(const char* sMessage);
299  ItemNotFound();
301  ItemNotFound(const ItemNotFound& inst);
303  virtual ~ItemNotFound() throw() {}
305  virtual const char* what() const throw();
306 };
307 
311 class LX_BASE_EXPORT OutOfRange : public Exception
312 {
313 public:
315  OutOfRange(const char* sMessage);
317  OutOfRange();
319  OutOfRange(const OutOfRange& inst);
321  virtual ~OutOfRange() throw() {}
323  virtual const char* what() const throw();
324 };
325 
329 class LX_BASE_EXPORT NotaNumber : public Exception
330 {
331 public:
333  NotaNumber(const char* sMessage);
335  NotaNumber();
337  NotaNumber(const NotaNumber& inst);
339  virtual ~NotaNumber() throw() {}
341  virtual const char* what() const throw();
342 };
343 
347 class LX_BASE_EXPORT FileException : public Exception
348 {
349 public:
351  FileException(const char* sMessage);
353  FileException();
355  FileException(const FileException& inst);
357  virtual ~FileException() throw() {}
359  virtual const char* what() const throw();
360 };
361 
365 class LX_BASE_EXPORT VectorWithNullMagnitude : public Exception
366 {
367 public:
369  VectorWithNullMagnitude(const char* sMessage);
375  virtual ~VectorWithNullMagnitude() throw() {}
377  virtual const char* what() const throw();
378 };
379 
383 class LX_BASE_EXPORT BadArguments : public Exception
384 {
385 public:
387  BadArguments(const char* sMessage);
389  BadArguments();
391  BadArguments(const BadArguments& inst);
393  virtual ~BadArguments() throw() {}
395  virtual const char* what() const throw();
396 };
397 
398 class LX_BASE_EXPORT GuidInUseException : public Base::Exception
399 {
400 public:
401  GuidInUseException() { _sErrMsg = "GUID in use"; }
402 
403  GuidInUseException(const char* sMessage) : Base::Exception(sMessage, "") {}
404 };
405 
406 
407 
408 class LX_BASE_EXPORT RuntimeError : public Base::Exception
409 {
410 public:
412  RuntimeError();
413  RuntimeError(const char* sMessage);
414  RuntimeError(const std::string& sMessage);
416  virtual ~RuntimeError() throw() {}
417 
418 };
419 
420 class LX_BASE_EXPORT ValueError : public Base::Exception
421 {
422 public:
424  ValueError();
425  ValueError(const char* sMessage);
426  ValueError(const std::string& sMessage);
428  virtual ~ValueError() throw() {}
429 };
430 
431 class LX_BASE_EXPORT CADKernelError : public Base::Exception
432 {
433 public:
435  CADKernelError();
436  CADKernelError(const char* sMessage);
437  CADKernelError(const std::string& sMessage);
439  virtual ~CADKernelError() throw() {}
440 };
441 
442 class LX_BASE_EXPORT TypeError : public Exception
443 {
444 public:
446  TypeError();
447  TypeError(const char* sMessage);
448  TypeError(const std::string& sMessage);
450  virtual ~TypeError() throw() {}
451 };
452 
453 class LX_BASE_EXPORT NotImplementedError : public Exception
454 {
455 public:
458  NotImplementedError(const char* sMessage);
459  NotImplementedError(const std::string& sMessage);
461  virtual ~NotImplementedError() throw() {}
462 };
463 
464 
465 class LX_BASE_EXPORT DivisionByZeroError : public Exception
466 {
467 public:
470  DivisionByZeroError(const char* sMessage);
471  DivisionByZeroError(const std::string& sMessage);
473  virtual ~DivisionByZeroError() throw() {}
474 };
475 
476 } // namespace Base
477 
478 #if !defined No_Exception && !defined No_Standard_OutOfRange
479 #define OutOfRange_Raise_if(CONDITION, MESSAGE) \
480  if (CONDITION) \
481  throw Base::OutOfRange(MESSAGE);
482 #else
483 #define OutOfRange_Raise_if(CONDITION, MESSAGE)
484 #endif
485 
486 #if !defined No_Exception && !defined No_Standard_ConstructionError
487 #define ConstructionError_Raise_if(CONDITION, MESSAGE) \
488  if (CONDITION) \
489  throw Base::ConstructionError(MESSAGE);
490 #else
491 #define ConstructionError_Raise_if(CONDITION, MESSAGE)
492 #endif
493 
494 #if !defined No_Exception && !defined No_gp_VectorWithNullMagnitude
495 #define VectorWithNullMagnitude_Raise_if(CONDITION, MESSAGE) \
496  if (CONDITION) \
497  throw Base::VectorWithNullMagnitude(MESSAGE);
498 #else
499 #define VectorWithNullMagnitude_Raise_if(CONDITION, MESSAGE)
500 #endif
501 
502 #if !defined No_Exception
503 #define NotaNumber_if(CONDITION, MESSAGE) \
504  if (CONDITION) \
505  throw Base::NotaNumber(MESSAGE);
506 #else
507 #define NotaNumber_if(CONDITION, MESSAGE)
508 #endif
509 
510 
511 #endif // __EXCEPTION_H__
Definition: Exception.h:217
Definition: Exception.h:257
Definition: Exception.h:329
virtual ~MemoryException()
Destruction.
Definition: Exception.h:244
virtual ~CADKernelError()
Destruction.
Definition: Exception.h:439
virtual ~Exception()
Definition: Exception.h:176
virtual ~NotaNumber()
Destruction.
Definition: Exception.h:339
void SetMessage(const char *sMessage)
Definition: Exception.h:248
virtual ~DivisionByZeroError()
Destruction.
Definition: Exception.h:473
bool getReported() const
Definition: Exception.h:191
Definition: Exception.h:398
Definition: Exception.h:442
virtual ~AbortException()
Destruction.
Definition: Exception.h:227
std::string _sErrDetail
Definition: Exception.h:204
virtual ~FailedNotDone()
Destruction.
Definition: Exception.h:285
Definition: Exception.h:383
virtual ~FileException()
Destruction.
Definition: Exception.h:357
virtual ~NotImplementedError()
Destruction.
Definition: Exception.h:461
virtual ~ItemNotFound()
Destruction.
Definition: Exception.h:303
virtual ~TypeError()
Destruction.
Definition: Exception.h:450
Definition: Exception.h:420
virtual ~BadArguments()
Destruction.
Definition: Exception.h:393
virtual ~ValueError()
Destruction.
Definition: Exception.h:428
Definition: Exception.h:293
std::string _sErrMsg
Definition: Exception.h:203
Definition: Exception.h:453
void setReported(bool reported)
Definition: Exception.h:197
virtual ~RuntimeError()
Destruction.
Definition: Exception.h:416
Definition: Exception.h:431
virtual ~VectorWithNullMagnitude()
Destruction.
Definition: Exception.h:375
Definition: AbstractXMLReader.h:5
Definition: Exception.h:408
Definition: Exception.h:236
Definition: Exception.h:170
Definition: Exception.h:311
GuidInUseException()
Definition: Exception.h:401
virtual ~OutOfRange()
Destruction.
Definition: Exception.h:321
Definition: Exception.h:275
Definition: Exception.h:365
virtual ~ConstructionError()
Destruction.
Definition: Exception.h:267
GuidInUseException(const char *sMessage)
Definition: Exception.h:403
Definition: Exception.h:465
Definition: Exception.h:347