From 32cbe58a1742eae352402441955ba8f679df208e Mon Sep 17 00:00:00 2001 From: asl Date: Fri, 21 Apr 2006 07:33:11 +0000 Subject: [PATCH] exception handler for light package --- src/LightApp/LightApp_ExceptionHandler.cxx | 81 ++++++++++++++++++++++ src/LightApp/LightApp_ExceptionHandler.h | 35 ++++++++++ src/LightApp/Makefile.in | 2 + 3 files changed, 118 insertions(+) create mode 100644 src/LightApp/LightApp_ExceptionHandler.cxx create mode 100644 src/LightApp/LightApp_ExceptionHandler.h diff --git a/src/LightApp/LightApp_ExceptionHandler.cxx b/src/LightApp/LightApp_ExceptionHandler.cxx new file mode 100644 index 000000000..22a6b2017 --- /dev/null +++ b/src/LightApp/LightApp_ExceptionHandler.cxx @@ -0,0 +1,81 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ +// +#include +#include "CASCatch.hxx" + +#include + +#include +#include + +#include + +/*!Constructor. Initialize by \a floatSignal.*/ +LightApp_ExceptionHandler::LightApp_ExceptionHandler( const bool floatSignal ) +: SUIT_ExceptionHandler() +{ + OSD::SetSignal( floatSignal ); +} + +/*!Try to call SUIT_ExceptionHandler::internalHandle(o, e), catch if failure.*/ +bool LightApp_ExceptionHandler::handleSignals( QObject* o, QEvent* e ) +{ + CASCatch_TRY { + SUIT_ExceptionHandler::internalHandle( o, e ); + } + CASCatch_CATCH(Standard_Failure) { + Handle(Standard_Failure) aFail = Standard_Failure::Caught(); + throw Standard_Failure( aFail->GetMessageString() ); + } + + return true; +} + +/*!Try to call handleSignals( o, e ), catch and show error message.*/ +bool LightApp_ExceptionHandler::handle( QObject* o, QEvent* e ) +{ + bool res = false; + QString title( "Fatal error" ); + + try { + res = handleSignals( o, e ); + } + catch( std::exception& ex ) + { + showMessage( title, QString( ex.what() ) ); + } + catch( Standard_Failure& e ) + { + showMessage( title, QString( e.GetMessageString() ) ); + } +#ifndef WNT + catch(...) + { + showMessage( title, "Unknown Exception" ); + } +#endif + + return res; +} + +/*!Create new SUIT_ExceptionHandler*/ +extern "C" LIGHTAPP_EXPORT SUIT_ExceptionHandler* getExceptionHandler() +{ + return new LightApp_ExceptionHandler( true ); +} diff --git a/src/LightApp/LightApp_ExceptionHandler.h b/src/LightApp/LightApp_ExceptionHandler.h new file mode 100644 index 000000000..dcd0eda33 --- /dev/null +++ b/src/LightApp/LightApp_ExceptionHandler.h @@ -0,0 +1,35 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ +// +#ifndef LIGHTAPP_EXCEPTIONHANDLER_H +#define LIGHTAPP_EXCEPTIONHANDLER_H + +#include +#include + +class LIGHTAPP_EXPORT LightApp_ExceptionHandler : public SUIT_ExceptionHandler +{ +public: + LightApp_ExceptionHandler( const bool ); + virtual bool handle( QObject*, QEvent* ); + +protected: + virtual bool handleSignals( QObject*, QEvent* ); +}; + +#endif diff --git a/src/LightApp/Makefile.in b/src/LightApp/Makefile.in index c26adb882..f846930c0 100755 --- a/src/LightApp/Makefile.in +++ b/src/LightApp/Makefile.in @@ -22,6 +22,7 @@ EXPORT_HEADERS= LightApp.h \ LightApp_Dialog.h \ LightApp_Displayer.h \ LightApp_Driver.h \ + LightApp_ExceptionHandler.h \ LightApp_HDFDriver.h \ LightApp_Module.h \ LightApp_ModuleDlg.h \ @@ -68,6 +69,7 @@ LIB_SRC= LightApp_AboutDlg.cxx \ LightApp_Dialog.cxx \ LightApp_Displayer.cxx \ LightApp_Driver.cxx \ + LightApp_ExceptionHandler.cxx \ LightApp_HDFDriver.cxx \ LightApp_Module.cxx \ LightApp_ModuleDlg.cxx \ -- 2.39.2