0022749: Segfault in HashCode() of Standard_Transient
[occt.git] / src / Standard / Standard_DefineException.hxx
1 #ifndef _Standard_DefineException_HeaderFile
2 #define _Standard_DefineException_HeaderFile
3
4 #include <Standard_Macro.hxx>
5 #include <Standard_DefineHandle.hxx>
6
7 //! Defines an exception class \a C1 that inherits an exception class \a C2.
8 /*! \a C2 must be Standard_Failure or its ancestor.
9     The macro defines empty constructor, copy constructor and static methods Raise() and NewInstance().
10     Since Standard_Failure implements class manipulated by handle, DEFINE_STANDARD_RTTI macro is also
11     added to enable RTTI.
12
13     When using DEFINE_STANDARD_EXCEPTION in your code make sure you also insert a macro
14     DEFINE_STANDARD_HANDLE(C1,C2) before it.
15
16     \sa IMPLEMENT_STANDARD_EXCEPTION.
17 */
18 #define DEFINE_STANDARD_EXCEPTION(C1,C2) \
19  \
20 class C1 : public C2 { \
21   Standard_EXPORT virtual void Throw() const; \
22 public: \
23   C1() : C2() {} \
24   C1(const Standard_CString AString) : C2(AString) {} \
25   Standard_EXPORT static void Raise(const Standard_CString aMessage = ""); \
26   Standard_EXPORT static void Raise(Standard_SStream& aReason); \
27   Standard_EXPORT static Handle(C1) NewInstance(const Standard_CString aMessage = ""); \
28  \
29   DEFINE_STANDARD_RTTI(C1) \
30 };
31
32
33 //! Implements an exception class \a C1 declared with DEFINE_STANDARD_EXCEPTION macro.
34 /*! If you are using IMPLEMENT_STANDARD_EXCEPTION in your code make sure you also call
35     IMPLEMENT_STANDARD_HANDLE(C1,C2) and IMPLEMENT_STANDARD_RTTIEXT(C1,C2).
36 */
37 #define IMPLEMENT_STANDARD_EXCEPTION(C1) \
38  \
39 void C1::Raise(Standard_SStream& aReason) \
40 { \
41   Handle(C1) _E = new C1; \
42   _E->Reraise (aReason); \
43 } \
44  \
45 void C1::Raise(const Standard_CString AString) \
46 { \
47   Handle(C1) _E = new C1; \
48   _E->Reraise(AString); \
49 } \
50  \
51 Handle(C1) C1::NewInstance(const Standard_CString aMessage) \
52 { \
53   return new C1(aMessage); \
54 } \
55 void C1::Throw () const \
56 { \
57   throw *this; \
58 }
59
60 #endif