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