1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #ifndef _Standard_DefineException_HeaderFile
15 #define _Standard_DefineException_HeaderFile
17 #include <Standard_Macro.hxx>
18 #include <Standard_DefineHandle.hxx>
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
26 When using DEFINE_STANDARD_EXCEPTION in your code make sure you also insert a macro
27 DEFINE_STANDARD_HANDLE(C1,C2) before it.
29 \sa IMPLEMENT_STANDARD_EXCEPTION.
31 #define DEFINE_STANDARD_EXCEPTION(C1,C2) \
33 class C1 : public C2 { \
34 Standard_EXPORT virtual void Throw() const; \
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 = ""); \
42 DEFINE_STANDARD_RTTI(C1) \
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).
50 #define IMPLEMENT_STANDARD_EXCEPTION(C1) \
52 void C1::Raise(Standard_SStream& aReason) \
54 Handle(C1) _E = new C1; \
55 _E->Reraise (aReason); \
58 void C1::Raise(const Standard_CString AString) \
60 Handle(C1) _E = new C1; \
61 _E->Reraise(AString); \
64 Handle(C1) C1::NewInstance(const Standard_CString aMessage) \
66 return new C1(aMessage); \
68 void C1::Throw () const \