973c2be1 |
1 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
2 | // |
973c2be1 |
3 | // This file is part of Open CASCADE Technology software library. |
b311480e |
4 | // |
973c2be1 |
5 | // This library is free software; you can redistribute it and / or modify it |
6 | // under the terms of the GNU Lesser General Public version 2.1 as published |
7 | // by the Free Software Foundation, with special exception defined in the file |
8 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
9 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
10 | // |
973c2be1 |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
b311480e |
13 | |
7fd59977 |
14 | #ifndef _Standard_DefineException_HeaderFile |
15 | #define _Standard_DefineException_HeaderFile |
16 | |
17 | #include <Standard_Macro.hxx> |
18 | #include <Standard_DefineHandle.hxx> |
19 | |
20 | //! Defines an exception class \a C1 that inherits an exception class \a C2. |
21 | /*! \a C2 must be Standard_Failure or its ancestor. |
22 | The macro defines empty constructor, copy constructor and static methods Raise() and NewInstance(). |
23 | Since Standard_Failure implements class manipulated by handle, DEFINE_STANDARD_RTTI macro is also |
24 | added to enable RTTI. |
25 | |
26 | When using DEFINE_STANDARD_EXCEPTION in your code make sure you also insert a macro |
27 | DEFINE_STANDARD_HANDLE(C1,C2) before it. |
28 | |
29 | \sa IMPLEMENT_STANDARD_EXCEPTION. |
30 | */ |
31 | #define DEFINE_STANDARD_EXCEPTION(C1,C2) \ |
32 | \ |
33 | class C1 : public C2 { \ |
34 | Standard_EXPORT virtual void Throw() const; \ |
35 | public: \ |
36 | C1() : C2() {} \ |
37 | C1(const Standard_CString AString) : C2(AString) {} \ |
38 | Standard_EXPORT static void Raise(const Standard_CString aMessage = ""); \ |
39 | Standard_EXPORT static void Raise(Standard_SStream& aReason); \ |
40 | Standard_EXPORT static Handle(C1) NewInstance(const Standard_CString aMessage = ""); \ |
41 | \ |
42 | DEFINE_STANDARD_RTTI(C1) \ |
43 | }; |
44 | |
45 | |
46 | //! Implements an exception class \a C1 declared with DEFINE_STANDARD_EXCEPTION macro. |
47 | /*! If you are using IMPLEMENT_STANDARD_EXCEPTION in your code make sure you also call |
48 | IMPLEMENT_STANDARD_HANDLE(C1,C2) and IMPLEMENT_STANDARD_RTTIEXT(C1,C2). |
49 | */ |
50 | #define IMPLEMENT_STANDARD_EXCEPTION(C1) \ |
51 | \ |
52 | void C1::Raise(Standard_SStream& aReason) \ |
53 | { \ |
54 | Handle(C1) _E = new C1; \ |
55 | _E->Reraise (aReason); \ |
56 | } \ |
57 | \ |
58 | void C1::Raise(const Standard_CString AString) \ |
59 | { \ |
60 | Handle(C1) _E = new C1; \ |
61 | _E->Reraise(AString); \ |
62 | } \ |
63 | \ |
64 | Handle(C1) C1::NewInstance(const Standard_CString aMessage) \ |
65 | { \ |
66 | return new C1(aMessage); \ |
67 | } \ |
68 | void C1::Throw () const \ |
69 | { \ |
70 | throw *this; \ |
71 | } |
72 | |
73 | #endif |