Salome HOME
Update from BR_V5_DEV 13Feb2009
[modules/gui.git] / src / CASCatch / CASCatch_Failure.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, 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.
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 // File   : CASCatch_Failure.cxx
23 // Author : Sergey RUIN, Open CASCADE S.A.S (sergey.ruin@opencascade.com)
24 //
25 #include "CASCatch_Failure.hxx"
26 #include "CASCatch_ErrorHandler.hxx"
27 #include <Standard_TypeMismatch.hxx>
28 #include <Standard_Type.hxx>
29 #include <string.h>
30
31 IMPLEMENT_STANDARD_HANDLE( CASCatch_Failure, Standard_Transient )
32 IMPLEMENT_STANDARD_RTTIEXT( CASCatch_Failure, Standard_Transient ) 
33
34
35 #ifndef NO_CXX_EXCEPTION
36 static Handle(CASCatch_Failure) RaisedError;
37 #endif
38
39 //================================================================================
40 /*! Public -
41  * \brief creates a CASCatch_Failure
42  */
43 //================================================================================ 
44 CASCatch_Failure::CASCatch_Failure () { myMessage = "Signal detected";}
45
46
47 //================================================================================
48 /*! Public -
49  * \brief creates a CASCatch_Failure with a message
50  * \param an exception message
51  */
52 //================================================================================ 
53 CASCatch_Failure::CASCatch_Failure (const Standard_CString AString) 
54 {
55   if(AString) {
56      myMessage = new Standard_Character[strlen(AString) + 1];
57      strcpy(myMessage,AString);
58   }
59 }
60
61 //================================================================================
62 /*! Public -
63  * \brief returns the last caught exception
64  */
65 //================================================================================ 
66 Handle(CASCatch_Failure) CASCatch_Failure::Caught() 
67 {
68 #ifdef NO_CXX_EXCEPTION
69   return CASCatch_ErrorHandler::LastCaughtError();
70 #else
71   return RaisedError ;
72 #endif
73 }
74
75 //================================================================================
76 /*! Public -
77  * \brief raises a CASCatch_Failure exception
78  * \param an exception message
79  */
80 //================================================================================ 
81 void CASCatch_Failure::Raise (const Standard_CString AString) 
82
83   Handle(CASCatch_Failure) E = new CASCatch_Failure()  ;
84   E->Reraise (AString) ;
85 }
86
87
88 //================================================================================
89 /*! Public -
90  * \brief re-raises a CASCatch_Failure exception
91  * \param an exception message
92  */
93 //================================================================================
94 void CASCatch_Failure::Reraise (const Standard_CString AString) 
95 {
96   if(AString){
97     myMessage = new Standard_Character[strlen(AString) + 1];
98     strcpy(myMessage,AString);
99   }
100
101 #ifdef NO_CXX_EXCEPTION
102   CASCatch_ErrorHandler::Error(this) ;
103   CASCatch_ErrorHandler::Abort();
104 #else
105   RaisedError = this ;
106   Throw() ;
107 #endif
108 }
109
110 //================================================================================
111 /*! Public -
112  * \brief returns an exception message
113  */
114 //================================================================================ 
115 Standard_CString CASCatch_Failure::GetError() const
116 {
117   return myMessage;
118 }
119
120 //================================================================================
121 /*! Public -
122  * \brief Is called when using standard C++ exceptions
123  */
124 //================================================================================ 
125 void CASCatch_Failure::Throw() const
126 {
127 #ifndef NO_CXX_EXCEPTION
128   throw CASCatch_Failure() ;
129 #endif
130 }
131