Salome HOME
Removed includes and libraries of OCC
[modules/kernel.git] / src / CASCatch / CASCatch_Failure.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
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.
8 // 
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.
13 //
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
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 #include "CASCatch_Failure.hxx"
21 #include "CASCatch_ErrorHandler.hxx"
22 #include <Standard_TypeMismatch.hxx>
23 #include <Standard_Type.hxx>
24 #include <string.h>
25
26 IMPLEMENT_STANDARD_HANDLE( CASCatch_Failure, Standard_Transient )
27 IMPLEMENT_STANDARD_RTTIEXT( CASCatch_Failure, Standard_Transient ) 
28
29
30 #ifndef NO_CXX_EXCEPTION
31 static Handle(CASCatch_Failure) RaisedError;
32 #endif
33
34 //================================================================================
35 /*! Public -
36  * \brief creates a CASCatch_Failure
37  */
38 //================================================================================ 
39 CASCatch_Failure::CASCatch_Failure () { myMessage = "Signal detected";}
40
41
42 //================================================================================
43 /*! Public -
44  * \brief creates a CASCatch_Failure with a message
45  * \param an exception message
46  */
47 //================================================================================ 
48 CASCatch_Failure::CASCatch_Failure (const Standard_CString AString) 
49 {
50   if(AString) {
51      myMessage = new Standard_Character[strlen(AString) + 1];
52      strcpy(myMessage,AString);
53   }
54 }
55
56 //================================================================================
57 /*! Public -
58  * \brief returns the last caught exception
59  */
60 //================================================================================ 
61 Handle(CASCatch_Failure) CASCatch_Failure::Caught() 
62 {
63 #ifdef NO_CXX_EXCEPTION
64   return CASCatch_ErrorHandler::LastCaughtError();
65 #else
66   return RaisedError ;
67 #endif
68 }
69
70 //================================================================================
71 /*! Public -
72  * \brief raises a CASCatch_Failure exception
73  * \param an exception message
74  */
75 //================================================================================ 
76 void CASCatch_Failure::Raise (const Standard_CString AString) 
77
78   Handle(CASCatch_Failure) E = new CASCatch_Failure()  ;
79   E->Reraise (AString) ;
80 }
81
82
83 //================================================================================
84 /*! Public -
85  * \brief re-raises a CASCatch_Failure exception
86  * \param an exception message
87  */
88 //================================================================================
89 void CASCatch_Failure::Reraise (const Standard_CString AString) 
90 {
91   if(AString){
92     myMessage = new Standard_Character[strlen(AString) + 1];
93     strcpy(myMessage,AString);
94   }
95
96 #ifdef NO_CXX_EXCEPTION
97   CASCatch_ErrorHandler::Error(this) ;
98   CASCatch_ErrorHandler::Abort();
99 #else
100   RaisedError = this ;
101   Throw() ;
102 #endif
103 }
104
105 //================================================================================
106 /*! Public -
107  * \brief returns an exception message
108  */
109 //================================================================================ 
110 Standard_CString CASCatch_Failure::GetError() const
111 {
112   return myMessage;
113 }
114
115 //================================================================================
116 /*! Public -
117  * \brief Is called when using standard C++ exceptions
118  */
119 //================================================================================ 
120 void CASCatch_Failure::Throw() const
121 {
122 #ifndef NO_CXX_EXCEPTION
123   throw CASCatch_Failure() ;
124 #endif
125 }
126