Salome HOME
Porting KERNEL on new XML reader.
[modules/kernel.git] / src / CASCatch / CASCatch_ErrorHandler.hxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20
21 #ifndef _CASCatch_ErrorHandler_HeaderFile
22 #define _CASCatch_ErrorHandler_HeaderFile
23
24 #include "CASCatch_Failure.hxx"
25
26 #include <stdlib.h>
27 #include <setjmp.h>
28
29
30 extern int K_SETJMP_CASCatch ;
31
32 /*!
33  * \class CASCatch_ErrorHandler
34  * \brief This class is an exception handler, private
35  *
36  */ 
37 class CASCatch_ErrorHandler 
38 {
39   friend class  CASCatch_Failure;     // To execute the raise exception.
40
41  public:
42  
43  Standard_EXPORT CASCatch_ErrorHandler();
44  Standard_EXPORT ~CASCatch_ErrorHandler();
45  Standard_EXPORT Standard_Boolean Catches (const Handle(Standard_Type)&);
46
47  private:
48   Standard_EXPORT static  void Abort();
49   Standard_EXPORT static  void Error(const Handle(CASCatch_Failure)&);
50   Standard_EXPORT static  Handle(CASCatch_Failure)  LastCaughtError();
51
52  //==== The fields ===========================================================
53  private:
54            CASCatch_ErrorHandler*   Previous;
55            Handle(CASCatch_Failure) CaughtError;
56
57  public:
58   jmp_buf      Label;
59
60 };
61
62 #undef CASCatch_TRY
63 #define CASCatch_TRY try
64
65 #undef CASCatch_CATCH
66 #define CASCatch_CATCH catch
67
68
69 #ifdef NO_CXX_EXCEPTION
70 # undef CASCatch_TRY
71 # undef CASCatch_CATCH
72
73 # if defined(DO_ABORT)
74   
75 #  define DoesNotAbort_CASCatch(aHandler) !(K_SETJMP_CASCatch = setjmp(aHandler.Label))
76
77 #  define CASCatch_TRY        CASCatch_ErrorHandler _Function; \
78                                 K_SETJMP_CASCatch = 1 ; \
79                                 if(DoesNotAbort_CASCatch(_Function))
80
81 # else  //If DO_ABORT is not defined
82 #  define DoesNotAbort_CASCatch(aHandler) !setjmp(aHandler.Label)
83
84 #  define CASCatch_TRY      CASCatch_ErrorHandler _Function; \
85                               if(DoesNotAbort_CASCatch(_Function))
86 # endif //DO_ABORT
87
88
89 # define CASCatch_CATCH(Error)   else if(_Function.Catches(STANDARD_TYPE(Error)))
90 #endif //NO_CXX_EXCEPTION
91
92 #endif //_CASCatch_ErrorHandler_HeaderFile