Salome HOME
Merge remote-tracking branch 'origin/V8_4_BR' into hydro/imps_2017
[modules/gui.git] / src / CASCatch / CASCatch_Failure.cxx
1 // Copyright (C) 2007-2016  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, or (at your option) any later version.
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_RTTIEXT(CASCatch_Failure, Standard_Transient)
33
34 #ifndef NO_CXX_EXCEPTION
35 static Handle(CASCatch_Failure) RaisedError;
36 #endif
37
38 //================================================================================
39 /*! Public -
40  * \brief creates a CASCatch_Failure
41  */
42 //================================================================================ 
43 CASCatch_Failure::CASCatch_Failure () { myMessage = (Standard_Character*)"Signal detected";}
44
45
46 //================================================================================
47 /*! Public -
48  * \brief creates a CASCatch_Failure with a message
49  * \param an exception message
50  */
51 //================================================================================ 
52 CASCatch_Failure::CASCatch_Failure (const Standard_CString AString) 
53 {
54   if(AString) {
55      myMessage = new Standard_Character[strlen(AString) + 1];
56      strcpy(myMessage,AString);
57   }
58 }
59
60 //================================================================================
61 /*! Public -
62  * \brief returns the last caught exception
63  */
64 //================================================================================ 
65 Handle(CASCatch_Failure) CASCatch_Failure::Caught() 
66 {
67 #ifdef NO_CXX_EXCEPTION
68   return CASCatch_ErrorHandler::LastCaughtError();
69 #else
70   return RaisedError ;
71 #endif
72 }
73
74 //================================================================================
75 /*! Public -
76  * \brief raises a CASCatch_Failure exception
77  * \param an exception message
78  */
79 //================================================================================ 
80 void CASCatch_Failure::Raise (const Standard_CString AString) 
81
82   Handle(CASCatch_Failure) E = new CASCatch_Failure()  ;
83   E->Reraise (AString) ;
84 }
85
86
87 //================================================================================
88 /*! Public -
89  * \brief re-raises a CASCatch_Failure exception
90  * \param an exception message
91  */
92 //================================================================================
93 void CASCatch_Failure::Reraise (const Standard_CString AString) 
94 {
95   if(AString){
96     myMessage = new Standard_Character[strlen(AString) + 1];
97     strcpy(myMessage,AString);
98   }
99
100 #ifdef NO_CXX_EXCEPTION
101   CASCatch_ErrorHandler::Error(this) ;
102   CASCatch_ErrorHandler::Abort();
103 #else
104   RaisedError = this ;
105   Throw() ;
106 #endif
107 }
108
109 //================================================================================
110 /*! Public -
111  * \brief returns an exception message
112  */
113 //================================================================================ 
114 Standard_CString CASCatch_Failure::GetError() const
115 {
116   return myMessage;
117 }
118
119 //================================================================================
120 /*! Public -
121  * \brief Is called when using standard C++ exceptions
122  */
123 //================================================================================ 
124 void CASCatch_Failure::Throw() const
125 {
126 #ifndef NO_CXX_EXCEPTION
127   throw CASCatch_Failure() ;
128 #endif
129 }
130