Back to index

salome-gui  6.5.0
CASCatch_ErrorHandler.hxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 // File   : CASCatch_ErrorHandler.hxx
00024 // Author : Sergey RUIN, Open CASCADE S.A.S (sergey.ruin@opencascade.com)
00025 //
00026 #ifndef CASCATCH_ERRORHANDLER_HXX
00027 #define CASCATCH_ERRORHANDLER_HXX
00028 
00029 #include "CASCatch_Failure.hxx"
00030 
00031 #include <stdlib.h>
00032 #include <setjmp.h>
00033 
00034 
00035 extern int K_SETJMP_CASCatch ;
00036 
00042 class CASCatch_ErrorHandler 
00043 {
00044   friend class  CASCatch_Failure;     // To execute the raise exception.
00045 
00046  public:
00047  
00048  Standard_EXPORT CASCatch_ErrorHandler();
00049  Standard_EXPORT ~CASCatch_ErrorHandler();
00050  Standard_EXPORT Standard_Boolean Catches (const Handle(Standard_Type)&);
00051 
00052  private:
00053   Standard_EXPORT static  void Abort();
00054   Standard_EXPORT static  void Error(const Handle(CASCatch_Failure)&);
00055   Standard_EXPORT static  Handle(CASCatch_Failure)  LastCaughtError();
00056 
00057  //==== The fields ===========================================================
00058  private:
00059            CASCatch_ErrorHandler*   Previous;
00060            Handle(CASCatch_Failure) CaughtError;
00061 
00062  public:
00063   jmp_buf      Label;
00064 
00065 };
00066 
00067 #undef CASCatch_TRY
00068 #define CASCatch_TRY try
00069 
00070 #undef CASCatch_CATCH
00071 #define CASCatch_CATCH catch
00072 
00073 
00074 #ifdef NO_CXX_EXCEPTION
00075 # undef CASCatch_TRY
00076 # undef CASCatch_CATCH
00077 
00078 # if defined(DO_ABORT)
00079   
00080 #  define DoesNotAbort_CASCatch(aHandler) !(K_SETJMP_CASCatch = setjmp(aHandler.Label))
00081 
00082 #  define CASCatch_TRY        CASCatch_ErrorHandler _Function; \
00083                                 K_SETJMP_CASCatch = 1 ; \
00084                                 if(DoesNotAbort_CASCatch(_Function))
00085 
00086 # else  // ! DO_ABORT
00087 #  define DoesNotAbort_CASCatch(aHandler) !setjmp(aHandler.Label)
00088 
00089 #  define CASCatch_TRY      CASCatch_ErrorHandler _Function; \
00090                               if(DoesNotAbort_CASCatch(_Function))
00091 # endif // DO_ABORT
00092 
00093 
00094 # define CASCatch_CATCH(Error)   else if(_Function.Catches(STANDARD_TYPE(Error)))
00095 #endif  // NO_CXX_EXCEPTION
00096 
00097 #endif  // CASCATCH_ERRORHANDLER_HXX