Salome HOME
Join modifications from branch OCC_debug_for_3_2_0b1
[modules/gui.git] / src / SalomeApp / SalomeApp_ExceptionHandler.cxx
1 // Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
2 // 
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.
7 // 
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/
18 //
19 #include "SalomeApp_ExceptionHandler.h"
20 #include "CASCatch.hxx"
21
22 #include <OSD.hxx>
23
24 #include <stdexcept>
25 #include <exception>
26
27 #include <qstring.h>
28
29 /*!Constructor. Initialize by \a floatSignal.*/
30 SalomeApp_ExceptionHandler::SalomeApp_ExceptionHandler( const bool floatSignal )
31 : SUIT_ExceptionHandler()
32 {
33   OSD::SetSignal( floatSignal );
34 }
35
36 /*!Try to call SUIT_ExceptionHandler::internalHandle(o, e), catch if failure.*/
37 bool SalomeApp_ExceptionHandler::handleSignals( QObject* o, QEvent* e )
38 {
39   CASCatch_TRY {   
40     SUIT_ExceptionHandler::internalHandle( o, e );
41   }
42   CASCatch_CATCH(Standard_Failure) {
43     Handle(Standard_Failure) aFail = Standard_Failure::Caught();          
44     throw Standard_Failure( aFail->GetMessageString() );
45   }
46   
47   return true;
48 }
49
50 /*!Try to call handleSignals( o, e ), catch and show error message.*/
51 bool SalomeApp_ExceptionHandler::handle( QObject* o, QEvent* e )
52 {
53   bool res = false;
54   QString title( "Fatal error" );
55
56   try {
57     res = handleSignals( o, e );
58   }
59   catch( std::exception& ex )
60   {
61     showMessage( title, QString( ex.what() ) );
62   }
63   catch( Standard_Failure& e )
64   {
65     showMessage( title, QString( e.GetMessageString() ) );
66   }
67 #ifndef WNT
68   catch(...)
69   {
70     showMessage( title, "Unknown Exception" );
71   }
72 #endif
73
74   return res;
75 }
76
77 /*!Create new SUIT_ExceptionHandler*/
78 extern "C" SALOMEAPP_EXPORT SUIT_ExceptionHandler* getExceptionHandler()
79 {
80   // MSV 2006-04-26: work around PAL12004 "VTK window => SIGFPE Arithmetic Exception Detected"
81   // We disable FPE signal as it was in earlier versions of SALOME. It is enabled
82   // only in debug mode if the environment variable DISABLE_FPE is not set to 1.
83   bool raiseFPE;
84 #ifdef _DEBUG_
85   raiseFPE = true;
86   char* envDisableFPE = getenv("DISABLE_FPE");
87   if (envDisableFPE && atoi(envDisableFPE))
88     raiseFPE = false;
89 #else
90   raiseFPE = false;
91 #endif
92   return new SalomeApp_ExceptionHandler( raiseFPE );
93 }