1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
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.
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.
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
17 // See http://www.salome-platform.org/
19 #include "SalomeApp_ExceptionHandler.h"
23 #include <Standard_Failure.hxx>
24 #include <Standard_ErrorHandler.hxx>
31 #include <CASCatch_CatchSignals.hxx>
32 #include <CASCatch_ErrorHandler.hxx>
33 #include <CASCatch_Failure.hxx>
36 /*!Constructor. Initialize by \a floatSignal.*/
37 SalomeApp_ExceptionHandler::SalomeApp_ExceptionHandler( const bool floatSignal )
38 : SUIT_ExceptionHandler()
40 OSD::SetSignal( floatSignal );
43 /*!Try to call SUIT_ExceptionHandler::internalHandle(o, e), catch if failure.*/
44 bool SalomeApp_ExceptionHandler::handleSignals( QObject* o, QEvent* e )
47 CASCatch_CatchSignals aCatchSignals;
48 aCatchSignals.Activate();
52 SUIT_ExceptionHandler::internalHandle( o, e );
54 CASCatch_CATCH(CASCatch_Failure) {
55 aCatchSignals.Deactivate();
56 Handle(CASCatch_Failure) aFail = CASCatch_Failure::Caught();
57 throw std::runtime_error( aFail->GetError() );
60 aCatchSignals.Deactivate();
72 /*!Try to call handleSignals( o, e ), catch and show error message.*/
73 bool SalomeApp_ExceptionHandler::handle( QObject* o, QEvent* e )
76 QString title( "Fatal error" );
79 res = handleSignals( o, e );
81 catch( std::exception& ex )
83 showMessage( title, QString( ex.what() ) );
85 catch( Standard_Failure& e )
87 showMessage( title, QString( e.GetMessageString() ) );
92 showMessage( title, "Unknown Exception" );
99 /*!Create new SUIT_ExceptionHandler*/
100 extern "C" SALOMEAPP_EXPORT SUIT_ExceptionHandler* getExceptionHandler()
102 return new SalomeApp_ExceptionHandler( true );