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