Salome HOME
Added slots for Copy and Paste operations
[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 SalomeApp_ExceptionHandler::SalomeApp_ExceptionHandler( const bool floatSignal )
14 : SUIT_ExceptionHandler()
15 {
16   OSD::SetSignal( floatSignal );
17 }
18
19 bool SalomeApp_ExceptionHandler::handleSignals( QObject* o, QEvent* e )
20 {
21   try {
22     SUIT_ExceptionHandler::internalHandle( o, e );
23   }
24   catch( Standard_Failure )
25   {
26     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
27     throw std::runtime_error( aFail->GetMessageString() );
28   }
29   return true;
30 }
31
32 #ifdef try
33 #undef try
34 #endif
35
36 #ifdef catch
37 #undef catch
38 #endif
39
40 bool SalomeApp_ExceptionHandler::handle( QObject* o, QEvent* e )
41 {
42   bool res = false;
43   QString title( "Fatal error" );
44
45   try {
46     res = handleSignals( o, e );
47   }
48   catch( std::exception& ex )
49   {
50     showMessage( title, QString( ex.what() ) );
51   }
52   catch( Standard_Failure& e )
53   {
54     showMessage( title, QString( e.GetMessageString() ) );
55   }
56 #ifndef WNT
57   catch(...)
58   {
59     showMessage( title, "Unknown Exception" );
60   }
61 #endif
62
63   return res;
64 }
65
66 extern "C" SALOMEAPP_EXPORT SUIT_ExceptionHandler* getExceptionHandler()
67 {
68   return new SalomeApp_ExceptionHandler( true );
69 }