1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "SalomeApp_ExceptionHandler.h"
20 #include "CASCatch.hxx"
29 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
30 #include <Standard_ErrorHandler.hxx>
31 #include <Standard_Failure.hxx>
33 #include "CASCatch.hxx"
36 /*!Constructor. Initialize by \a floatSignal.*/
37 SalomeApp_ExceptionHandler::SalomeApp_ExceptionHandler( const bool floatSignal )
38 : SUIT_ExceptionHandler()
40 // JFA 2006-09-28: PAL10867: suppress signal catching,
41 // if environment variable DISABLE_SIGNALS_CATCHING is set to 1.
42 // Commonly this is used with "noexcepthandler" option.
43 char* envNoCatchSignals = getenv("NOT_INTERCEPT_SIGNALS");
44 if (!envNoCatchSignals || !atoi(envNoCatchSignals))
46 OSD::SetSignal( floatSignal );
50 /*!Try to call SUIT_ExceptionHandler::internalHandle(o, e), catch if failure.*/
51 bool SalomeApp_ExceptionHandler::handleSignals( QObject* o, QEvent* e )
53 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
59 SUIT_ExceptionHandler::internalHandle( o, e );
61 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
62 catch(Standard_Failure) {
64 CASCatch_CATCH(Standard_Failure) {
66 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
67 throw Standard_Failure( aFail->GetMessageString() );
73 /*!Try to call handleSignals( o, e ), catch and show error message.*/
74 bool SalomeApp_ExceptionHandler::handle( QObject* o, QEvent* e )
77 QString title( "Fatal error" );
80 res = handleSignals( o, e );
82 catch( std::exception& ex )
84 showMessage( title, QString( ex.what() ) );
86 catch( Standard_Failure& e )
88 showMessage( title, QString( e.GetMessageString() ) );
93 showMessage( title, "Unknown Exception" );
100 /*!Create new SUIT_ExceptionHandler*/
102 extern "C" SALOMEAPP_EXPORT SUIT_ExceptionHandler* getExceptionHandler()
104 // MSV 2006-04-26: work around PAL12004 "VTK window => SIGFPE Arithmetic Exception Detected"
105 // We disable FPE signal as it was in earlier versions of SALOME. It is enabled
106 // only in debug mode if the environment variable DISABLE_FPE is not set to 1.
108 #if defined(_DEBUG_) | defined(_DEBUG) //the Last for WNT default settings
110 char* envDisableFPE = getenv("DISABLE_FPE");
111 if (envDisableFPE && atoi(envDisableFPE))
117 return new SalomeApp_ExceptionHandler( raiseFPE );