1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "SalomeApp_ExceptionHandler.h"
24 #include "Utils_CorbaException.hxx"
26 #include "CASCatch.hxx"
27 #include "Basics_OCCTVersion.hxx"
36 #if OCC_VERSION_LARGE > 0x06010000
37 #include <Standard_ErrorHandler.hxx>
38 #include <Standard_Failure.hxx>
40 #include "CASCatch.hxx"
43 /*!Constructor. Initialize by \a floatSignal.*/
44 SalomeApp_ExceptionHandler::SalomeApp_ExceptionHandler( const bool floatSignal )
45 : SUIT_ExceptionHandler()
47 // JFA 2006-09-28: PAL10867: suppress signal catching,
48 // if environment variable DISABLE_SIGNALS_CATCHING is set to 1.
49 // Commonly this is used with "noexcepthandler" option.
50 char* envNoCatchSignals = getenv("NOT_INTERCEPT_SIGNALS");
51 if (!envNoCatchSignals || !atoi(envNoCatchSignals))
53 OSD::SetSignal( floatSignal );
57 /*!Try to call SUIT_ExceptionHandler::internalHandle(o, e), catch if failure.*/
58 bool SalomeApp_ExceptionHandler::handleSignals( QObject* o, QEvent* e )
60 #if OCC_VERSION_LARGE > 0x06010000
66 SUIT_ExceptionHandler::internalHandle( o, e );
68 #if OCC_VERSION_LARGE > 0x06010000
69 catch(Standard_Failure) {
71 CASCatch_CATCH(Standard_Failure) {
73 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
74 throw Standard_Failure( aFail->GetMessageString() );
80 /*!Try to call handleSignals( o, e ), catch and show error message.*/
81 bool SalomeApp_ExceptionHandler::handle( QObject* o, QEvent* e )
84 QString title( "Fatal error" );
87 res = handleSignals( o, e );
89 catch( std::exception& ex )
91 showMessage( title, QString( ex.what() ) );
93 catch( Standard_Failure& e )
95 showMessage( title, QString( e.GetMessageString() ) );
97 catch( SALOME::SALOME_Exception& ex)
99 showMessage( title, QString( ex.details.text));
104 showMessage( title, "Unknown Exception" );
111 /*!Create new SUIT_ExceptionHandler*/
112 extern "C" SALOMEAPP_EXPORT SUIT_ExceptionHandler* getExceptionHandler()
114 // MSV 2006-04-26: work around PAL12004 "VTK window => SIGFPE Arithmetic Exception Detected"
115 // We disable FPE signal as it was in earlier versions of SALOME. It is enabled
116 // only in debug mode if the environment variable DISABLE_FPE is not set to 1.
118 #if defined(_DEBUG_) | defined(_DEBUG) //the Last for WNT default settings
120 char* envDisableFPE = getenv("DISABLE_FPE");
121 if (envDisableFPE && atoi(envDisableFPE))
127 return new SalomeApp_ExceptionHandler( raiseFPE );