Back to index

salome-gui  6.5.0
SalomeApp_ExceptionHandler.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 #include "SalomeApp_ExceptionHandler.h"
00024 
00025 #include "CASCatch.hxx"
00026 #include "Basics_OCCTVersion.hxx"
00027 
00028 #include <OSD.hxx>
00029 
00030 #include <stdexcept>
00031 #include <exception>
00032 
00033 #include <QString>
00034 
00035 #if OCC_VERSION_LARGE > 0x06010000
00036   #include <Standard_ErrorHandler.hxx>
00037   #include <Standard_Failure.hxx>
00038 #else
00039   #include "CASCatch.hxx"
00040 #endif
00041 
00043 SalomeApp_ExceptionHandler::SalomeApp_ExceptionHandler( const bool floatSignal )
00044 : SUIT_ExceptionHandler()
00045 {
00046   // JFA 2006-09-28: PAL10867: suppress signal catching,
00047   // if environment variable DISABLE_SIGNALS_CATCHING is set to 1.
00048   // Commonly this is used with "noexcepthandler" option.
00049   char* envNoCatchSignals = getenv("NOT_INTERCEPT_SIGNALS");
00050   if (!envNoCatchSignals || !atoi(envNoCatchSignals))
00051   {
00052     OSD::SetSignal( floatSignal );
00053   }
00054 }
00055 
00057 bool SalomeApp_ExceptionHandler::handleSignals( QObject* o, QEvent* e )
00058 {
00059 #if OCC_VERSION_LARGE > 0x06010000
00060   try {
00061     OCC_CATCH_SIGNALS;
00062 #else
00063   CASCatch_TRY {
00064 #endif
00065     SUIT_ExceptionHandler::internalHandle( o, e );
00066   }
00067 #if OCC_VERSION_LARGE > 0x06010000
00068   catch(Standard_Failure) {
00069 #else
00070   CASCatch_CATCH(Standard_Failure) {
00071 #endif
00072     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
00073     throw Standard_Failure( aFail->GetMessageString() );
00074   }
00075 
00076   return true;
00077 }
00078 
00080 bool SalomeApp_ExceptionHandler::handle( QObject* o, QEvent* e )
00081 {
00082   bool res = false;
00083   QString title( "Fatal error" );
00084 
00085   try {
00086     res = handleSignals( o, e );
00087   }
00088   catch( std::exception& ex )
00089   {
00090     showMessage( title, QString( ex.what() ) );
00091   }
00092   catch( Standard_Failure& e )
00093   {
00094     showMessage( title, QString( e.GetMessageString() ) );
00095   }
00096 #ifndef WIN32
00097   catch(...)
00098   {
00099     showMessage( title, "Unknown Exception" );
00100   }
00101 #endif
00102 
00103   return res;
00104 }
00105 
00107 extern "C" SALOMEAPP_EXPORT SUIT_ExceptionHandler* getExceptionHandler()
00108 {
00109   // MSV 2006-04-26: work around PAL12004 "VTK window => SIGFPE Arithmetic Exception Detected"
00110   // We disable FPE signal as it was in earlier versions of SALOME. It is enabled
00111   // only in debug mode if the environment variable DISABLE_FPE is not set to 1.
00112   bool raiseFPE;
00113 #if defined(_DEBUG_) | defined(_DEBUG) //the Last for WNT default settings
00114   raiseFPE = true;
00115   char* envDisableFPE = getenv("DISABLE_FPE");
00116   if (envDisableFPE && atoi(envDisableFPE))
00117     raiseFPE = false;
00118 #else
00119   raiseFPE = false;
00120 #endif
00121 
00122   return new SalomeApp_ExceptionHandler( raiseFPE );
00123 }