Salome HOME
Update comments
[modules/gui.git] / src / SalomeApp / SalomeApp_ExceptionHandler.cxx
1 #include "SalomeApp_ExceptionHandler.h"
2
3 #include <OSD.hxx>
4
5 #include <Standard_Failure.hxx>
6 #include <Standard_ErrorHandler.hxx>
7
8 #include <stdexcept>
9 #include <exception>
10
11 #include <qstring.h>
12
13 /*!Constructor. Initialize by \a floatSignal.*/
14 SalomeApp_ExceptionHandler::SalomeApp_ExceptionHandler( const bool floatSignal )
15 : SUIT_ExceptionHandler()
16 {
17   OSD::SetSignal( floatSignal );
18 }
19
20 /*!Try to call SUIT_ExceptionHandler::internalHandle(o, e), catch if failure.*/
21 bool SalomeApp_ExceptionHandler::handleSignals( QObject* o, QEvent* e )
22 {
23   try {
24     SUIT_ExceptionHandler::internalHandle( o, e );
25   }
26   catch( Standard_Failure )
27   {
28     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
29     throw std::runtime_error( aFail->GetMessageString() );
30   }
31   return true;
32 }
33
34 #ifdef try
35 #undef try
36 #endif
37
38 #ifdef catch
39 #undef catch
40 #endif
41
42 /*!Try to call handleSignals( o, e ), catch and show error message.*/
43 bool SalomeApp_ExceptionHandler::handle( QObject* o, QEvent* e )
44 {
45   bool res = false;
46   QString title( "Fatal error" );
47
48   try {
49     res = handleSignals( o, e );
50   }
51   catch( std::exception& ex )
52   {
53     showMessage( title, QString( ex.what() ) );
54   }
55   catch( Standard_Failure& e )
56   {
57     showMessage( title, QString( e.GetMessageString() ) );
58   }
59 #ifndef WNT
60   catch(...)
61   {
62     showMessage( title, "Unknown Exception" );
63   }
64 #endif
65
66   return res;
67 }
68
69 /*!Create new SUIT_ExceptionHandler*/
70 extern "C" SALOMEAPP_EXPORT SUIT_ExceptionHandler* getExceptionHandler()
71 {
72   return new SalomeApp_ExceptionHandler( true );
73 }