]> SALOME platform Git repositories - modules/kernel.git/blob - src/CASCatch/CASCatch_Failure.cxx
Salome HOME
PR: merge from branch BR_UnitTests tag mergeto_trunk_17oct05
[modules/kernel.git] / src / CASCatch / CASCatch_Failure.cxx
1 #include "CASCatch_Failure.hxx"
2 #include "CASCatch_ErrorHandler.hxx"
3 #include <Standard_TypeMismatch.hxx>
4 #include <Standard_Type.hxx>
5 #include <string.h>
6
7 IMPLEMENT_STANDARD_HANDLE( CASCatch_Failure, Standard_Transient )
8 IMPLEMENT_STANDARD_RTTIEXT( CASCatch_Failure, Standard_Transient ) 
9
10
11 #ifndef NO_CXX_EXCEPTION
12 static Handle(CASCatch_Failure) RaisedError;
13 #endif
14
15 //================================================================================
16 /*! Public -
17  * \brief creates a CASCatch_Failure
18  */
19 //================================================================================ 
20 CASCatch_Failure::CASCatch_Failure () { myMessage = "Signal detected";}
21
22
23 //================================================================================
24 /*! Public -
25  * \brief creates a CASCatch_Failure with a message
26  * \param an exception message
27  */
28 //================================================================================ 
29 CASCatch_Failure::CASCatch_Failure (const Standard_CString AString) 
30 {
31   if(AString) {
32      myMessage = new Standard_Character[strlen(AString) + 1];
33      strcpy(myMessage,AString);
34   }
35 }
36
37 //================================================================================
38 /*! Public -
39  * \brief returns the last caught exception
40  */
41 //================================================================================ 
42 Handle(CASCatch_Failure) CASCatch_Failure::Caught() 
43 {
44 #ifdef NO_CXX_EXCEPTION
45   return CASCatch_ErrorHandler::LastCaughtError();
46 #else
47   return RaisedError ;
48 #endif
49 }
50
51 //================================================================================
52 /*! Public -
53  * \brief raises a CASCatch_Failure exception
54  * \param an exception message
55  */
56 //================================================================================ 
57 void CASCatch_Failure::Raise (const Standard_CString AString) 
58
59   Handle(CASCatch_Failure) E = new CASCatch_Failure()  ;
60   E->Reraise (AString) ;
61 }
62
63
64 //================================================================================
65 /*! Public -
66  * \brief re-raises a CASCatch_Failure exception
67  * \param an exception message
68  */
69 //================================================================================
70 void CASCatch_Failure::Reraise (const Standard_CString AString) 
71 {
72   if(AString){
73     myMessage = new Standard_Character[strlen(AString) + 1];
74     strcpy(myMessage,AString);
75   }
76
77 #ifdef NO_CXX_EXCEPTION
78   CASCatch_ErrorHandler::Error(this) ;
79   CASCatch_ErrorHandler::Abort();
80 #else
81   RaisedError = this ;
82   Throw() ;
83 #endif
84 }
85
86 //================================================================================
87 /*! Public -
88  * \brief returns an exception message
89  */
90 //================================================================================ 
91 Standard_CString CASCatch_Failure::GetError() const
92 {
93   return myMessage;
94 }
95
96 //================================================================================
97 /*! Public -
98  * \brief Is called when using standard C++ exceptions
99  */
100 //================================================================================ 
101 void CASCatch_Failure::Throw() const
102 {
103 #ifndef NO_CXX_EXCEPTION
104   throw CASCatch_Failure() ;
105 #endif
106 }
107