Salome HOME
0023505: Sigsegv with fuse on cylinder and cone
[modules/gui.git] / src / SalomeApp / SalomeApp_ExceptionHandler.cxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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, or (at your option) any later version.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "SalomeApp_ExceptionHandler.h"
24 #include "Utils_CorbaException.hxx"
25
26 #include <OSD.hxx>
27
28 #include <stdexcept>
29 #include <exception>
30
31 #include <QString>
32
33 #include <Standard_ErrorHandler.hxx>
34 #include <Standard_Failure.hxx>
35
36
37 /*!Constructor. Initialize by \a floatSignal.*/
38 SalomeApp_ExceptionHandler::SalomeApp_ExceptionHandler( const bool floatSignal )
39 : SUIT_ExceptionHandler()
40 {
41   // JFA 2006-09-28: PAL10867: suppress signal catching,
42   // if environment variable DISABLE_SIGNALS_CATCHING is set to 1.
43   // Commonly this is used with "noexcepthandler" option.
44   char* envNoCatchSignals = getenv("NOT_INTERCEPT_SIGNALS");
45   if (!envNoCatchSignals || !atoi(envNoCatchSignals))
46   {
47     OSD::SetSignal( floatSignal );
48   }
49 }
50
51 /*!Try to call SUIT_ExceptionHandler::internalHandle(o, e), catch if failure.*/
52 bool SalomeApp_ExceptionHandler::handleSignals( QObject* o, QEvent* e )
53 {
54   bool result = true;
55
56   try
57   {
58     OCC_CATCH_SIGNALS;
59     result = SUIT_ExceptionHandler::internalHandle( o, e );
60   }
61   catch( Standard_Failure& e )
62   {
63     throw Standard_Failure( e.GetMessageString() );
64   }
65
66   return result;
67 }
68
69 /*!Try to call handleSignals( o, e ), catch and show error message.*/
70 bool SalomeApp_ExceptionHandler::handle( QObject* o, QEvent* e )
71 {
72   bool res = false;
73   QString title( "Fatal error" );
74
75   try {
76     res = handleSignals( o, e );
77   }
78   catch( std::exception& ex )
79   {
80     showMessage( title, QString( ex.what() ) );
81   }
82   catch( Standard_Failure& e )
83   {
84     showMessage( title, QString( e.GetMessageString() ) );
85   }
86   catch( SALOME::SALOME_Exception& ex)
87   {
88     showMessage( title, QString( ex.details.text));
89   }
90 #ifndef WIN32
91   catch(...)
92   {
93     showMessage( title, "Unknown Exception" );
94   }
95 #endif
96
97   return res;
98 }
99
100 /*!Create new SUIT_ExceptionHandler*/
101 extern "C" SALOMEAPP_EXPORT SUIT_ExceptionHandler* getExceptionHandler()
102 {
103   // MSV 2006-04-26: work around PAL12004 "VTK window => SIGFPE Arithmetic Exception Detected"
104   // We disable FPE signal as it was in earlier versions of SALOME. It is enabled
105   // only in debug mode if the environment variable DISABLE_FPE is not set to 1.
106   bool raiseFPE;
107   raiseFPE = false;
108
109 #if defined(_DEBUG_) | defined(_DEBUG) //the Last for WIN32 default settings
110   char* envEnableFPE = getenv("ENABLE_FPE");
111   if (envEnableFPE && atoi(envEnableFPE))
112     raiseFPE = true;
113 #endif
114
115   return new SalomeApp_ExceptionHandler( raiseFPE );
116 }