1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : CASCatch_ErrorHandler.cxx
24 // Author : Sergey RUIN, Open CASCADE S.A.S (sergey.ruin@opencascade.com)
26 #ifdef NO_CXX_EXCEPTION
28 #include "CASCatch_ErrorHandler.hxx"
30 // During setjmp()/longjmp() K_SETJMP_CASCatch is non zero (try)
31 // So if there is an abort request and if K_SETJMP_CASCatch is non zero, the abort
32 // request will be ignored. If the abort request do a raise during a setjmp
33 // or a longjmp, there will be a "terminating SEGV" impossible to handle.
36 Standard_EXPORT int K_SETJMP_CASCatch = 0 ;
38 static Handle(CASCatch_Failure) GlbError; //Last caught Error, Null if there is no error
40 static CASCatch_ErrorHandler* Top = 0; //The top of the Errors Stack
42 //=======================================================================
43 //function : CASCatch_ErrorHandler
44 //purpose : Constructor
45 //=======================================================================
46 CASCatch_ErrorHandler::CASCatch_ErrorHandler ()
50 CaughtError.Nullify();
54 //=======================================================================
55 //function : ~CASCatch_ErrorHandler
56 //purpose : Destructor : Delete the ErrorHandler and Abort if there is a 'Error'.
57 //=======================================================================
58 CASCatch_ErrorHandler::~CASCatch_ErrorHandler()
61 if( !GlbError.IsNull() ) Abort();
64 //=======================================================================
65 //function : Abort: make a longjmp to the saved Context.
66 //purpose : Abort if there is a non null 'Error'
67 //=======================================================================
68 void CASCatch_ErrorHandler::Abort ()
70 //==== Check if can do the "longjmp" =======================================
71 if(Top == NULL || Top->Label == NULL) {
72 cout << "*** Abort *** an exception was raised, but no catch was found." << endl;
73 cout << "\t... The exception is:" << GlbError;
78 if ( K_SETJMP_CASCatch )
79 cout << "Recursive abort ===> Terminating SEGV ..." << endl ;
80 K_SETJMP_CASCatch = 1 ;
83 longjmp(Top->Label, Standard_True);
86 //=======================================================================
88 //purpose : If there is a 'Error', and it is in good type
89 // returns True and clean 'Error', else returns False.
90 //=======================================================================
91 Standard_Boolean CASCatch_ErrorHandler::Catches
92 (const Handle(Standard_Type)& AType)
95 K_SETJMP_CASCatch = 0 ;
98 return Standard_False;
100 if(GlbError->IsKind(AType)){
101 CaughtError = GlbError;
103 return Standard_True;
105 return Standard_False;
109 //=======================================================================
110 //function : LastCaughtError
112 //=======================================================================
113 Handle(CASCatch_Failure) CASCatch_ErrorHandler::LastCaughtError()
115 return Top->CaughtError;
118 //=======================================================================
121 //=======================================================================
122 void CASCatch_ErrorHandler::Error(const Handle(CASCatch_Failure)& aError)