]> SALOME platform Git repositories - modules/gui.git/blob - src/SalomeApp/SalomeApp_ExceptionHandler.cxx
Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[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/ or email : webmaster.salome@opencascade.com
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 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
30   #include <Standard_ErrorHandler.hxx>
31   #include <Standard_Failure.hxx>
32 #else
33   #include "CASCatch.hxx"
34 #endif
35
36 /*!Constructor. Initialize by \a floatSignal.*/
37 SalomeApp_ExceptionHandler::SalomeApp_ExceptionHandler( const bool floatSignal )
38 : SUIT_ExceptionHandler()
39 {
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))
45   {
46     OSD::SetSignal( floatSignal );
47   }
48 }
49
50 /*!Try to call SUIT_ExceptionHandler::internalHandle(o, e), catch if failure.*/
51 bool SalomeApp_ExceptionHandler::handleSignals( QObject* o, QEvent* e )
52 {
53 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
54   try {
55     OCC_CATCH_SIGNALS;
56 #else
57   CASCatch_TRY {
58 #endif
59     SUIT_ExceptionHandler::internalHandle( o, e );
60   }
61 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
62   catch(Standard_Failure) {
63 #else
64   CASCatch_CATCH(Standard_Failure) {
65 #endif
66     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
67     throw Standard_Failure( aFail->GetMessageString() );
68   }
69
70   return true;
71 }
72
73 /*!Try to call handleSignals( o, e ), catch and show error message.*/
74 bool SalomeApp_ExceptionHandler::handle( QObject* o, QEvent* e )
75 {
76   bool res = false;
77   QString title( "Fatal error" );
78
79   try {
80     res = handleSignals( o, e );
81   }
82   catch( std::exception& ex )
83   {
84     showMessage( title, QString( ex.what() ) );
85   }
86   catch( Standard_Failure& e )
87   {
88     showMessage( title, QString( e.GetMessageString() ) );
89   }
90 #ifndef WNT
91   catch(...)
92   {
93     showMessage( title, "Unknown Exception" );
94   }
95 #endif
96
97   return res;
98 }
99
100 /*!Create new SUIT_ExceptionHandler*/
101
102 extern "C" SALOMEAPP_EXPORT SUIT_ExceptionHandler* getExceptionHandler()
103 {
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.
107   bool raiseFPE;
108 #if defined(_DEBUG_) | defined(_DEBUG) //the Last for WNT default settings
109   raiseFPE = true;
110   char* envDisableFPE = getenv("DISABLE_FPE");
111   if (envDisableFPE && atoi(envDisableFPE))
112     raiseFPE = false;
113 #else
114   raiseFPE = false;
115 #endif
116
117   return new SalomeApp_ExceptionHandler( raiseFPE );
118 }