OpenLexocad  28.0
Exception.h
Go to the documentation of this file.
1 #pragma once
2 #include <string>
3 
4 
5 /* MACROS FOR THROWING EXCEPTIONS */
6 
16 
17 #ifdef _MSC_VER
18 
19 #define THROW(exception) \
20  { \
21  exception myexcp; \
22  myexcp.setDebugInformation(__FILE__, __LINE__, __FUNCSIG__); \
23  throw myexcp; \
24  }
25 #define THROWM(exception, message) \
26  { \
27  exception myexcp(message); \
28  myexcp.setDebugInformation(__FILE__, __LINE__, __FUNCSIG__); \
29  throw myexcp; \
30  }
31 #define THROWMF_FILEEXCEPTION(message, filenameorfileinfo) \
32  { \
33  FileException myexcp(message, filenameorfileinfo); \
34  myexcp.setDebugInformation(__FILE__, __LINE__, __FUNCSIG__); \
35  throw myexcp; \
36  }
37 
38 #define THROWT(exception) \
39  { \
40  exception myexcp; \
41  myexcp.setDebugInformation(__FILE__, __LINE__, __FUNCSIG__); \
42  myexcp.setTranslatable(true); \
43  throw myexcp; \
44  }
45 #define THROWMT(exception, message) \
46  { \
47  exception myexcp(message); \
48  myexcp.setDebugInformation(__FILE__, __LINE__, __FUNCSIG__); \
49  myexcp.setTranslatable(true); \
50  throw myexcp; \
51  }
52 #define THROWMFT_FILEEXCEPTION(message, filenameorfileinfo) \
53  { \
54  FileException myexcp(message, filenameorfileinfo); \
55  myexcp.setDebugInformation(__FILE__, __LINE__, __FUNCSIG__); \
56  myexcp.setTranslatable(true); \
57  throw myexcp; \
58  }
59 
60 #elif defined(__GNUC__)
61 
62 #define THROW(exception) \
63  { \
64  exception myexcp; \
65  myexcp.setDebugInformation(__FILE__, __LINE__, __PRETTY_FUNCTION__); \
66  throw myexcp; \
67  }
68 #define THROWM(exception, message) \
69  { \
70  exception myexcp(message); \
71  myexcp.setDebugInformation(__FILE__, __LINE__, __PRETTY_FUNCTION__); \
72  throw myexcp; \
73  }
74 #define THROWMF_FILEEXCEPTION(message, filenameorfileinfo) \
75  { \
76  FileException myexcp(message, filenameorfileinfo); \
77  myexcp.setDebugInformation(__FILE__, __LINE__, __PRETTY_FUNCTION__); \
78  throw myexcp; \
79  }
80 
81 #define THROWT(exception) \
82  { \
83  exception myexcp; \
84  myexcp.setDebugInformation(__FILE__, __LINE__, __PRETTY_FUNCTION__); \
85  myexcp.setTranslatable(true); \
86  throw myexcp; \
87  }
88 #define THROWMT(exception, message) \
89  { \
90  exception myexcp(message); \
91  myexcp.setDebugInformation(__FILE__, __LINE__, __PRETTY_FUNCTION__); \
92  myexcp.setTranslatable(true); \
93  throw myexcp; \
94  }
95 #define THROWMFT_FILEEXCEPTION(message, filenameorfileinfo) \
96  { \
97  FileException myexcp(message, filenameorfileinfo); \
98  myexcp.setDebugInformation(__FILE__, __LINE__, __PRETTY_FUNCTION__); \
99  myexcp.setTranslatable(true); \
100  throw myexcp; \
101  }
102 
103 #else
104 
105 #define THROW(exception) \
106  { \
107  exception myexcp; \
108  myexcp.setDebugInformation(__FILE__, __LINE__, __func__); \
109  throw myexcp; \
110  }
111 #define THROWM(exception, message) \
112  { \
113  exception myexcp(message); \
114  myexcp.setDebugInformation(__FILE__, __LINE__, __func__); \
115  throw myexcp; \
116  }
117 #define THROWMF_FILEEXCEPTION(message, filenameorfileinfo) \
118  { \
119  FileException myexcp(message, filenameorfileinfo); \
120  myexcp.setDebugInformation(__FILE__, __LINE__, __func__); \
121  throw myexcp; \
122  }
123 
124 #define THROWT(exception) \
125  { \
126  exception myexcp; \
127  myexcp.setDebugInformation(__FILE__, __LINE__, __func__); \
128  myexcp.setTranslatable(true); \
129  throw myexcp; \
130  }
131 #define THROWMT(exception, message) \
132  { \
133  exception myexcp(message); \
134  myexcp.setDebugInformation(__FILE__, __LINE__, __func__); \
135  myexcp.setTranslatable(true); \
136  throw myexcp; \
137  }
138 #define THROWMFT_FILEEXCEPTION(message, filenameorfileinfo) \
139  { \
140  FileException myexcp(message, filenameorfileinfo); \
141  myexcp.setDebugInformation(__FILE__, __LINE__, __func__); \
142  myexcp.setTranslatable(true); \
143  throw myexcp; \
144  }
145 
146 
147 #endif
148 
149 #define FC_THROWM(_exception, _msg) \
150  do \
151  { \
152  std::stringstream ss; \
153  ss << _msg; \
154  THROWM(_exception, ss.str().c_str()); \
155  } while (0)
156 
157 #define THROW_CON_ERR_IF(_condition_, _msg_) \
158  if (_condition_) \
159  throw Base::ConstructionError(_msg_);
160 
161 #define THROW_FAIL_NDONE_IF(_condition_, _msg_) \
162  if (_condition_) \
163  throw Base::FailedNotDone(_msg_);
164 
165 namespace Base
166 {
167 class LX_BASE_EXPORT Exception
168 {
169 public:
170  Exception(const char* sMessage, const char* detail);
171  Exception(void);
172  Exception(const Exception& inst);
173  virtual ~Exception() throw() {}
174 
176 
177  virtual const char* what(void) const throw();
178  virtual const char* detail(void) const throw();
179 
180  void ReportException(void) const;
181 
182  inline void SetMessage(const char* sMessage);
183 
184  inline std::string getFile() const;
185  inline int getLine() const;
186  inline std::string getFunction() const;
187  inline bool getTranslatable() const;
188  inline bool getReported() const { return _isReported; }
189 
192  inline void setDebugInformation(const std::string& file, const int line, const std::string& function);
193  inline void setTranslatable(bool translatable);
194  inline void setReported(bool reported) { _isReported = reported; }
195 
196 protected:
197 #ifdef _MSC_VER
198 #pragma warning(disable : 4251)
199 #endif
200  std::string _sErrMsg;
201  std::string _sErrDetail;
202  std::string _file{ "" };
203  int _line{ -1 };
204  std::string _function{ "" };
205  bool _isTranslatable{ false };
206  mutable bool _isReported{ false };
207 };
208 
209 
214 class LX_BASE_EXPORT AbortException : public Exception
215 {
216 public:
218  AbortException(const char* sMessage);
224  virtual ~AbortException() throw() {}
226  virtual const char* what() const throw();
227 };
228 
233 class LX_BASE_EXPORT MemoryException : public Exception
234 {
235 public:
241  virtual ~MemoryException() throw() {}
242 };
243 
244 
245 inline void Exception::SetMessage(const char* sMessage)
246 {
247  _sErrMsg = sMessage;
248 }
249 
254 class LX_BASE_EXPORT ConstructionError : public Exception
255 {
256 public:
258  ConstructionError(const char* sMessage);
264  virtual ~ConstructionError() throw() {}
266  virtual const char* what() const throw();
267 };
268 
272 class LX_BASE_EXPORT FailedNotDone : public Exception
273 {
274 public:
276  FailedNotDone(const char* sMessage);
282  virtual ~FailedNotDone() throw() {}
284  virtual const char* what() const throw();
285 };
286 
290 class LX_BASE_EXPORT ItemNotFound : public Exception
291 {
292 public:
294  ItemNotFound(const char* sMessage);
300  virtual ~ItemNotFound() throw() {}
302  virtual const char* what() const throw();
303 };
304 
308 class LX_BASE_EXPORT OutOfRange : public Exception
309 {
310 public:
312  OutOfRange(const char* sMessage);
316  OutOfRange(const OutOfRange& inst);
318  virtual ~OutOfRange() throw() {}
320  virtual const char* what() const throw();
321 };
322 
326 class LX_BASE_EXPORT NotaNumber : public Exception
327 {
328 public:
330  NotaNumber(const char* sMessage);
334  NotaNumber(const NotaNumber& inst);
336  virtual ~NotaNumber() throw() {}
338  virtual const char* what() const throw();
339 };
340 
344 class LX_BASE_EXPORT FileException : public Exception
345 {
346 public:
348  FileException(const char* sMessage);
354  virtual ~FileException() throw() {}
356  virtual const char* what() const throw();
357 };
358 
362 class LX_BASE_EXPORT VectorWithNullMagnitude : public Exception
363 {
364 public:
366  VectorWithNullMagnitude(const char* sMessage);
372  virtual ~VectorWithNullMagnitude() throw() {}
374  virtual const char* what() const throw();
375 };
376 
380 class LX_BASE_EXPORT BadArguments : public Exception
381 {
382 public:
384  BadArguments(const char* sMessage);
390  virtual ~BadArguments() throw() {}
392  virtual const char* what() const throw();
393 };
394 
395 class LX_BASE_EXPORT GuidInUseException : public Base::Exception
396 {
397 public:
398  GuidInUseException() { _sErrMsg = "GUID in use"; }
399 
400  GuidInUseException(const char* sMessage) : Base::Exception(sMessage, "") {}
401 };
402 
403 
404 
405 class LX_BASE_EXPORT RuntimeError : public Base::Exception
406 {
407 public:
410  RuntimeError(const char* sMessage);
411  RuntimeError(const std::string& sMessage);
413  virtual ~RuntimeError() throw() {}
414 
415 };
416 
417 class LX_BASE_EXPORT ValueError : public Base::Exception
418 {
419 public:
422  ValueError(const char* sMessage);
423  ValueError(const std::string& sMessage);
425  virtual ~ValueError() throw() {}
426 };
427 
428 class LX_BASE_EXPORT CADKernelError : public Base::Exception
429 {
430 public:
433  CADKernelError(const char* sMessage);
434  CADKernelError(const std::string& sMessage);
436  virtual ~CADKernelError() throw() {}
437 };
438 
439 class LX_BASE_EXPORT TypeError : public Exception
440 {
441 public:
444  TypeError(const char* sMessage);
445  TypeError(const std::string& sMessage);
447  virtual ~TypeError() throw() {}
448 };
449 
450 class LX_BASE_EXPORT NotImplementedError : public Exception
451 {
452 public:
455  NotImplementedError(const char* sMessage);
456  NotImplementedError(const std::string& sMessage);
458  virtual ~NotImplementedError() throw() {}
459 };
460 
461 
462 class LX_BASE_EXPORT DivisionByZeroError : public Exception
463 {
464 public:
467  DivisionByZeroError(const char* sMessage);
468  DivisionByZeroError(const std::string& sMessage);
470  virtual ~DivisionByZeroError() throw() {}
471 };
472 
473 } // namespace Base
474 
475 #if !defined No_Exception && !defined No_Standard_OutOfRange
476 #define OutOfRange_Raise_if(CONDITION, MESSAGE) \
477  if (CONDITION) \
478  throw Base::OutOfRange(MESSAGE);
479 #else
480 #define OutOfRange_Raise_if(CONDITION, MESSAGE)
481 #endif
482 
483 #if !defined No_Exception && !defined No_Standard_ConstructionError
484 #define ConstructionError_Raise_if(CONDITION, MESSAGE) \
485  if (CONDITION) \
486  throw Base::ConstructionError(MESSAGE);
487 #else
488 #define ConstructionError_Raise_if(CONDITION, MESSAGE)
489 #endif
490 
491 #if !defined No_Exception && !defined No_gp_VectorWithNullMagnitude
492 #define VectorWithNullMagnitude_Raise_if(CONDITION, MESSAGE) \
493  if (CONDITION) \
494  throw Base::VectorWithNullMagnitude(MESSAGE);
495 #else
496 #define VectorWithNullMagnitude_Raise_if(CONDITION, MESSAGE)
497 #endif
498 
499 #if !defined No_Exception
500 #define NotaNumber_if(CONDITION, MESSAGE) \
501  if (CONDITION) \
502  throw Base::NotaNumber(MESSAGE);
503 #else
504 #define NotaNumber_if(CONDITION, MESSAGE)
505 #endif
Base::FailedNotDone::FailedNotDone
FailedNotDone(const FailedNotDone &inst)
Construction.
Base::BadArguments::what
virtual const char * what() const
Description of the exception.
Base::OutOfRange::OutOfRange
OutOfRange(const OutOfRange &inst)
Construction.
Base::NotaNumber
Definition: Exception.h:327
Base::VectorWithNullMagnitude::~VectorWithNullMagnitude
virtual ~VectorWithNullMagnitude()
Destruction.
Definition: Exception.h:372
Base::GuidInUseException
Definition: Exception.h:396
Base::Exception::getLine
int getLine() const
Base::DivisionByZeroError::~DivisionByZeroError
virtual ~DivisionByZeroError()
Destruction.
Definition: Exception.h:470
Base::TypeError::TypeError
TypeError(const char *sMessage)
Base::DivisionByZeroError
Definition: Exception.h:463
Base::ItemNotFound::~ItemNotFound
virtual ~ItemNotFound()
Destruction.
Definition: Exception.h:300
Base::VectorWithNullMagnitude::what
virtual const char * what() const
Description of the exception.
Base::FailedNotDone::what
virtual const char * what() const
Description of the exception.
Base::ItemNotFound
Definition: Exception.h:291
Base::FileException::what
virtual const char * what() const
Description of the exception.
Base::OutOfRange
Definition: Exception.h:309
Base::MemoryException::MemoryException
MemoryException()
Construction.
Base::NotImplementedError::NotImplementedError
NotImplementedError(const char *sMessage)
Base::Exception::Exception
Exception(const char *sMessage, const char *detail)
Base::Exception::getFile
std::string getFile() const
Base::NotaNumber::NotaNumber
NotaNumber()
Construction.
Base::Exception::Exception
Exception(void)
Base::AbortException::what
virtual const char * what() const
Description of the exception.
Base::NotImplementedError::NotImplementedError
NotImplementedError()
Construction.
Base::BadArguments::BadArguments
BadArguments(const char *sMessage)
Construction.
Base::FileException::~FileException
virtual ~FileException()
Destruction.
Definition: Exception.h:354
Base::FileException::FileException
FileException()
Construction.
Base::DivisionByZeroError::DivisionByZeroError
DivisionByZeroError()
Construction.
Base::Exception::SetMessage
void SetMessage(const char *sMessage)
Definition: Exception.h:245
Base::Exception::getTranslatable
bool getTranslatable() const
Base::NotaNumber::what
virtual const char * what() const
Description of the exception.
Base::MemoryException
Definition: Exception.h:234
Base::TypeError::~TypeError
virtual ~TypeError()
Destruction.
Definition: Exception.h:447
Base::OutOfRange::~OutOfRange
virtual ~OutOfRange()
Destruction.
Definition: Exception.h:318
Base::VectorWithNullMagnitude
Definition: Exception.h:363
Base::Exception::~Exception
virtual ~Exception()
Definition: Exception.h:173
Base::ConstructionError::~ConstructionError
virtual ~ConstructionError()
Destruction.
Definition: Exception.h:264
Base::VectorWithNullMagnitude::VectorWithNullMagnitude
VectorWithNullMagnitude()
Construction.
Base::RuntimeError
Definition: Exception.h:406
Base::CADKernelError
Definition: Exception.h:429
Base::Exception::ReportException
void ReportException(void) const
Base::ValueError::ValueError
ValueError(const std::string &sMessage)
Base::FileException::FileException
FileException(const FileException &inst)
Construction.
Base::OutOfRange::OutOfRange
OutOfRange()
Construction.
Base::ItemNotFound::ItemNotFound
ItemNotFound(const char *sMessage)
Construction.
Base::TypeError::TypeError
TypeError()
Construction.
Base::ValueError
Definition: Exception.h:418
Base::OutOfRange::what
virtual const char * what() const
Description of the exception.
Base::Exception
Definition: Exception.h:168
Base::BadArguments::~BadArguments
virtual ~BadArguments()
Destruction.
Definition: Exception.h:390
Base::BadArguments::BadArguments
BadArguments(const BadArguments &inst)
Construction.
Base::ConstructionError
Definition: Exception.h:255
Base::ConstructionError::ConstructionError
ConstructionError()
Construction.
Base::Exception::operator=
Exception & operator=(const Exception &inst)
Base::DivisionByZeroError::DivisionByZeroError
DivisionByZeroError(const char *sMessage)
Base::Exception::what
virtual const char * what(void) const
Base::FailedNotDone
Definition: Exception.h:273
Base::Exception::setTranslatable
void setTranslatable(bool translatable)
Base::Exception::_sErrDetail
std::string _sErrDetail
Definition: Exception.h:201
Base::ValueError::ValueError
ValueError(const char *sMessage)
Base::RuntimeError::RuntimeError
RuntimeError(const char *sMessage)
Base::FailedNotDone::FailedNotDone
FailedNotDone()
Construction.
Base::ItemNotFound::ItemNotFound
ItemNotFound()
Construction.
Base::CADKernelError::CADKernelError
CADKernelError(const char *sMessage)
Base::Exception::getReported
bool getReported() const
Definition: Exception.h:188
Base::ConstructionError::ConstructionError
ConstructionError(const ConstructionError &inst)
Construction.
Base::RuntimeError::RuntimeError
RuntimeError(const std::string &sMessage)
Base::MemoryException::~MemoryException
virtual ~MemoryException()
Destruction.
Definition: Exception.h:241
Base::DivisionByZeroError::DivisionByZeroError
DivisionByZeroError(const std::string &sMessage)
Base::ConstructionError::ConstructionError
ConstructionError(const char *sMessage)
Construction.
Base::ConstructionError::what
virtual const char * what() const
Description of the exception.
Base::Exception::Exception
Exception(const Exception &inst)
Base::Exception::getFunction
std::string getFunction() const
Base::AbortException::AbortException
AbortException()
Construction.
Base::RuntimeError::~RuntimeError
virtual ~RuntimeError()
Destruction.
Definition: Exception.h:413
Base::BadArguments::BadArguments
BadArguments()
Construction.
Base::ValueError::~ValueError
virtual ~ValueError()
Destruction.
Definition: Exception.h:425
Base::MemoryException::MemoryException
MemoryException(const MemoryException &inst)
Construction.
Base::RuntimeError::RuntimeError
RuntimeError()
Construction.
Base::AbortException::~AbortException
virtual ~AbortException()
Destruction.
Definition: Exception.h:224
Base::Exception::setDebugInformation
void setDebugInformation(const std::string &file, const int line, const std::string &function)
Base::FailedNotDone::~FailedNotDone
virtual ~FailedNotDone()
Destruction.
Definition: Exception.h:282
Base::FailedNotDone::FailedNotDone
FailedNotDone(const char *sMessage)
Construction.
Base::CADKernelError::CADKernelError
CADKernelError(const std::string &sMessage)
Base::OutOfRange::OutOfRange
OutOfRange(const char *sMessage)
Construction.
Base::AbortException::AbortException
AbortException(const AbortException &inst)
Construction.
Base::BadArguments
Definition: Exception.h:381
Base::FileException::FileException
FileException(const char *sMessage)
Construction.
Base::VectorWithNullMagnitude::VectorWithNullMagnitude
VectorWithNullMagnitude(const char *sMessage)
Construction.
Base::FileException
Definition: Exception.h:345
Base::VectorWithNullMagnitude::VectorWithNullMagnitude
VectorWithNullMagnitude(const VectorWithNullMagnitude &inst)
Construction.
Base::NotImplementedError
Definition: Exception.h:451
Base::CADKernelError::CADKernelError
CADKernelError()
Construction.
Base::CADKernelError::~CADKernelError
virtual ~CADKernelError()
Destruction.
Definition: Exception.h:436
Base::ItemNotFound::ItemNotFound
ItemNotFound(const ItemNotFound &inst)
Construction.
Base::NotaNumber::~NotaNumber
virtual ~NotaNumber()
Destruction.
Definition: Exception.h:336
Base::NotImplementedError::~NotImplementedError
virtual ~NotImplementedError()
Destruction.
Definition: Exception.h:458
Base::AbortException
Definition: Exception.h:215
Base::ValueError::ValueError
ValueError()
Construction.
Base::GuidInUseException::GuidInUseException
GuidInUseException()
Definition: Exception.h:398
Base::AbortException::AbortException
AbortException(const char *sMessage)
Construction.
Base::GuidInUseException::GuidInUseException
GuidInUseException(const char *sMessage)
Definition: Exception.h:400
Base::NotImplementedError::NotImplementedError
NotImplementedError(const std::string &sMessage)
Base::TypeError
Definition: Exception.h:440
Base::NotaNumber::NotaNumber
NotaNumber(const NotaNumber &inst)
Construction.
Base::TypeError::TypeError
TypeError(const std::string &sMessage)
Base
Definition: AbstractXMLReader.h:5
Base::Exception::setReported
void setReported(bool reported)
Definition: Exception.h:194
Base::Exception::_sErrMsg
std::string _sErrMsg
Definition: Exception.h:200
Base::Exception::detail
virtual const char * detail(void) const
Base::NotaNumber::NotaNumber
NotaNumber(const char *sMessage)
Construction.
Base::ItemNotFound::what
virtual const char * what() const
Description of the exception.