1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #ifdef NO_CXX_EXCEPTION
23 #include "CASCatch_ErrorHandler.hxx"
25 // During setjmp()/longjmp() K_SETJMP_CASCatch is non zero (try)
26 // So if there is an abort request and if K_SETJMP_CASCatch is non zero, the abort
27 // request will be ignored. If the abort request do a raise during a setjmp
28 // or a longjmp, there will be a "terminating SEGV" impossible to handle.
31 Standard_EXPORT int K_SETJMP_CASCatch = 0 ;
33 static Handle(CASCatch_Failure) GlbError; //Last caught Error, Null if there is no error
35 static CASCatch_ErrorHandler* Top = 0; //The top of the Errors Stack
37 //=======================================================================
38 //function : CASCatch_ErrorHandler
39 //purpose : Constructor
40 //=======================================================================
41 CASCatch_ErrorHandler::CASCatch_ErrorHandler ()
45 CaughtError.Nullify();
49 //=======================================================================
50 //function : ~CASCatch_ErrorHandler
51 //purpose : Destructor : Delete the ErrorHandler and Abort if there is a 'Error'.
52 //=======================================================================
53 CASCatch_ErrorHandler::~CASCatch_ErrorHandler()
56 if( !GlbError.IsNull() ) Abort();
59 //=======================================================================
60 //function : Abort: make a longjmp to the saved Context.
61 //purpose : Abort if there is a non null 'Error'
62 //=======================================================================
63 void CASCatch_ErrorHandler::Abort ()
65 //==== Check if can do the "longjmp" =======================================
66 if(Top == NULL || Top->Label == NULL) {
67 cout << "*** Abort *** an exception was raised, but no catch was found." << endl;
68 cout << "\t... The exception is:" << GlbError;
73 if ( K_SETJMP_CASCatch )
74 cout << "Recursive abort ===> Terminating SEGV ..." << endl ;
75 K_SETJMP_CASCatch = 1 ;
78 longjmp(Top->Label, Standard_True);
81 //=======================================================================
83 //purpose : If there is a 'Error', and it is in good type
84 // returns True and clean 'Error', else returns False.
85 //=======================================================================
86 Standard_Boolean CASCatch_ErrorHandler::Catches
87 (const Handle(Standard_Type)& AType)
90 K_SETJMP_CASCatch = 0 ;
93 return Standard_False;
95 if(GlbError->IsKind(AType)){
96 CaughtError = GlbError;
100 return Standard_False;
104 //=======================================================================
105 //function : LastCaughtError
107 //=======================================================================
108 Handle(CASCatch_Failure) CASCatch_ErrorHandler::LastCaughtError()
110 return Top->CaughtError;
113 //=======================================================================
116 //=======================================================================
117 void CASCatch_ErrorHandler::Error(const Handle(CASCatch_Failure)& aError)