]> SALOME platform Git repositories - modules/gui.git/blob - src/SalomeApp/SalomeApp_ExceptionHandler.cxx
Salome HOME
bf868e0bfe697d272807a208f2ea34fb3628b110
[modules/gui.git] / src / SalomeApp / SalomeApp_ExceptionHandler.cxx
1 // Copyright (C) 2007-2012  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.
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
25 #include "CASCatch.hxx"
26 #include "Basics_OCCTVersion.hxx"
27
28 #include <OSD.hxx>
29
30 #include <stdexcept>
31 #include <exception>
32
33 #include <QString>
34
35 #if OCC_VERSION_LARGE > 0x06010000
36   #include <Standard_ErrorHandler.hxx>
37   #include <Standard_Failure.hxx>
38 #else
39   #include "CASCatch.hxx"
40 #endif
41
42 /*!Constructor. Initialize by \a floatSignal.*/
43 SalomeApp_ExceptionHandler::SalomeApp_ExceptionHandler( const bool floatSignal )
44 : SUIT_ExceptionHandler()
45 {
46   // JFA 2006-09-28: PAL10867: suppress signal catching,
47   // if environment variable DISABLE_SIGNALS_CATCHING is set to 1.
48   // Commonly this is used with "noexcepthandler" option.
49   char* envNoCatchSignals = getenv("NOT_INTERCEPT_SIGNALS");
50   if (!envNoCatchSignals || !atoi(envNoCatchSignals))
51   {
52     OSD::SetSignal( floatSignal );
53   }
54 }
55
56 /*!Try to call SUIT_ExceptionHandler::internalHandle(o, e), catch if failure.*/
57 bool SalomeApp_ExceptionHandler::handleSignals( QObject* o, QEvent* e )
58 {
59 #if OCC_VERSION_LARGE > 0x06010000
60   try {
61     OCC_CATCH_SIGNALS;
62 #else
63   CASCatch_TRY {
64 #endif
65     SUIT_ExceptionHandler::internalHandle( o, e );
66   }
67 #if OCC_VERSION_LARGE > 0x06010000
68   catch(Standard_Failure) {
69 #else
70   CASCatch_CATCH(Standard_Failure) {
71 #endif
72     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
73     throw Standard_Failure( aFail->GetMessageString() );
74   }
75
76   return true;
77 }
78
79 /*!Try to call handleSignals( o, e ), catch and show error message.*/
80 bool SalomeApp_ExceptionHandler::handle( QObject* o, QEvent* e )
81 {
82   bool res = false;
83   QString title( "Fatal error" );
84
85   try {
86     res = handleSignals( o, e );
87   }
88   catch( std::exception& ex )
89   {
90     showMessage( title, QString( ex.what() ) );
91   }
92   catch( Standard_Failure& e )
93   {
94     showMessage( title, QString( e.GetMessageString() ) );
95   }
96 #ifndef WIN32
97   catch(...)
98   {
99     showMessage( title, "Unknown Exception" );
100   }
101 #endif
102
103   return res;
104 }
105
106 /*!Create new SUIT_ExceptionHandler*/
107 extern "C" SALOMEAPP_EXPORT SUIT_ExceptionHandler* getExceptionHandler()
108 {
109   // MSV 2006-04-26: work around PAL12004 "VTK window => SIGFPE Arithmetic Exception Detected"
110   // We disable FPE signal as it was in earlier versions of SALOME. It is enabled
111   // only in debug mode if the environment variable DISABLE_FPE is not set to 1.
112   bool raiseFPE;
113 #if defined(_DEBUG_) | defined(_DEBUG) //the Last for WNT default settings
114   raiseFPE = true;
115   char* envDisableFPE = getenv("DISABLE_FPE");
116   if (envDisableFPE && atoi(envDisableFPE))
117     raiseFPE = false;
118 #else
119   raiseFPE = false;
120 #endif
121
122   return new SalomeApp_ExceptionHandler( raiseFPE );
123 }