Back to index

salome-gui  6.5.0
CASCatch_Failure.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 // File   : CASCatch_Failure.cxx
00024 // Author : Sergey RUIN, Open CASCADE S.A.S (sergey.ruin@opencascade.com)
00025 //
00026 #include "CASCatch_Failure.hxx"
00027 #include "CASCatch_ErrorHandler.hxx"
00028 #include <Standard_TypeMismatch.hxx>
00029 #include <Standard_Type.hxx>
00030 #include <string.h>
00031 
00032 IMPLEMENT_STANDARD_HANDLE( CASCatch_Failure, Standard_Transient )
00033 IMPLEMENT_STANDARD_RTTIEXT( CASCatch_Failure, Standard_Transient ) 
00034 
00035 
00036 #ifndef NO_CXX_EXCEPTION
00037 static Handle(CASCatch_Failure) RaisedError;
00038 #endif
00039 
00040 //================================================================================
00044 //================================================================================ 
00045 CASCatch_Failure::CASCatch_Failure () { myMessage = (Standard_Character*)"Signal detected";}
00046 
00047 
00048 //================================================================================
00053 //================================================================================ 
00054 CASCatch_Failure::CASCatch_Failure (const Standard_CString AString) 
00055 {
00056   if(AString) {
00057      myMessage = new Standard_Character[strlen(AString) + 1];
00058      strcpy(myMessage,AString);
00059   }
00060 }
00061 
00062 //================================================================================
00066 //================================================================================ 
00067 Handle(CASCatch_Failure) CASCatch_Failure::Caught() 
00068 {
00069 #ifdef NO_CXX_EXCEPTION
00070   return CASCatch_ErrorHandler::LastCaughtError();
00071 #else
00072   return RaisedError ;
00073 #endif
00074 }
00075 
00076 //================================================================================
00081 //================================================================================ 
00082 void CASCatch_Failure::Raise (const Standard_CString AString) 
00083 { 
00084   Handle(CASCatch_Failure) E = new CASCatch_Failure()  ;
00085   E->Reraise (AString) ;
00086 }
00087 
00088 
00089 //================================================================================
00094 //================================================================================
00095 void CASCatch_Failure::Reraise (const Standard_CString AString) 
00096 {
00097   if(AString){
00098     myMessage = new Standard_Character[strlen(AString) + 1];
00099     strcpy(myMessage,AString);
00100   }
00101 
00102 #ifdef NO_CXX_EXCEPTION
00103   CASCatch_ErrorHandler::Error(this) ;
00104   CASCatch_ErrorHandler::Abort();
00105 #else
00106   RaisedError = this ;
00107   Throw() ;
00108 #endif
00109 }
00110 
00111 //================================================================================
00115 //================================================================================ 
00116 Standard_CString CASCatch_Failure::GetError() const
00117 {
00118   return myMessage;
00119 }
00120 
00121 //================================================================================
00125 //================================================================================ 
00126 void CASCatch_Failure::Throw() const
00127 {
00128 #ifndef NO_CXX_EXCEPTION
00129   throw CASCatch_Failure() ;
00130 #endif
00131 }
00132