Salome HOME
5619b46f3f784893b17ac0b5d07ffb976e83fc17
[modules/gui.git] / src / CASCatch / CASCatch_ErrorHandler.hxx
1 // Copyright (C) 2007-2023  CEA, EDF, 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, or (at your option) any later version.
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
23 // File   : CASCatch_ErrorHandler.hxx
24 // Author : Sergey RUIN, Open CASCADE S.A.S (sergey.ruin@opencascade.com)
25 //
26 #ifndef CASCATCH_ERRORHANDLER_HXX
27 #define CASCATCH_ERRORHANDLER_HXX
28
29 #include "CASCatch_Failure.hxx"
30
31 #include <stdlib.h>
32 #include <setjmp.h>
33
34
35 extern int K_SETJMP_CASCatch ;
36
37 /*!
38  * \class CASCatch_ErrorHandler
39  * \brief This class is an exception handler, private
40  *
41  */ 
42 class CASCatch_ErrorHandler 
43 {
44   friend class  CASCatch_Failure;     // To execute the raise exception.
45
46  public:
47  
48  Standard_EXPORT CASCatch_ErrorHandler();
49  Standard_EXPORT ~CASCatch_ErrorHandler();
50  Standard_EXPORT Standard_Boolean Catches (const Handle(Standard_Type)&);
51
52  private:
53   Standard_EXPORT static  void Abort();
54   Standard_EXPORT static  void Error(const Handle(CASCatch_Failure)&);
55   Standard_EXPORT static  Handle(CASCatch_Failure)  LastCaughtError();
56
57  //==== The fields ===========================================================
58  private:
59            CASCatch_ErrorHandler*   Previous;
60            Handle(CASCatch_Failure) CaughtError;
61
62  public:
63   jmp_buf      Label;
64
65 };
66
67 #undef CASCatch_TRY
68 #define CASCatch_TRY try
69
70 #undef CASCatch_CATCH
71 #define CASCatch_CATCH catch
72
73
74 #ifdef NO_CXX_EXCEPTION
75 # undef CASCatch_TRY
76 # undef CASCatch_CATCH
77
78 # if defined(DO_ABORT)
79   
80 #  define DoesNotAbort_CASCatch(aHandler) !(K_SETJMP_CASCatch = setjmp(aHandler.Label))
81
82 #  define CASCatch_TRY        CASCatch_ErrorHandler _Function; \
83                                 K_SETJMP_CASCatch = 1 ; \
84                                 if(DoesNotAbort_CASCatch(_Function))
85
86 # else  // ! DO_ABORT
87 #  define DoesNotAbort_CASCatch(aHandler) !setjmp(aHandler.Label)
88
89 #  define CASCatch_TRY      CASCatch_ErrorHandler _Function; \
90                               if(DoesNotAbort_CASCatch(_Function))
91 # endif // DO_ABORT
92
93
94 # define CASCatch_CATCH(Error)   else if(_Function.Catches(STANDARD_TYPE(Error)))
95 #endif  // NO_CXX_EXCEPTION
96
97 #endif  // CASCATCH_ERRORHANDLER_HXX