00001 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE 00002 // 00003 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, 00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 00005 // 00006 // This library is free software; you can redistribute it and/or 00007 // modify it under the terms of the GNU Lesser General Public 00008 // License as published by the Free Software Foundation; either 00009 // version 2.1 of the License. 00010 // 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 // Lesser General Public License for more details. 00015 // 00016 // You should have received a copy of the GNU Lesser General Public 00017 // License along with this library; if not, write to the Free Software 00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 // 00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com 00021 // 00022 // KERNEL Utils : common utils for KERNEL 00023 // File : Utils_ExceptHandlers.hxx 00024 // Author : Oksana Tchebanova 00025 // Module : KERNEL 00026 // $Header: 00027 // 00028 #ifndef Utils_ExceptHandlers_HeaderFile 00029 #define Utils_ExceptHandlers_HeaderFile 00030 00031 #include "SALOME_Utils.hxx" 00032 00033 #include <stdexcept> 00034 00035 typedef void (*PVF)(); 00036 00037 class UTILS_EXPORT Unexpect { //save / retrieve unexpected exceptions treatment 00038 PVF old; 00039 public : 00040 #ifndef WIN32 00041 Unexpect( PVF f ) 00042 { old = std::set_unexpected(f); } 00043 ~Unexpect() { std::set_unexpected(old); } 00044 #else 00045 Unexpect( PVF f ) 00046 { old = ::set_unexpected(f); } 00047 ~Unexpect() { ::set_unexpected(old); } 00048 #endif 00049 }; 00050 00051 class UTILS_EXPORT Terminate {//save / retrieve terminate function 00052 00053 PVF old; 00054 public : 00055 #ifndef WIN32 00056 Terminate( PVF f ) 00057 { old = std::set_terminate(f); } 00058 ~Terminate() { std::set_terminate(old); } 00059 #else 00060 Terminate( PVF f ) 00061 { old = ::set_terminate(f); } 00062 ~Terminate() { ::set_terminate(old); } 00063 #endif 00064 }; 00065 00066 #define UNEXPECT_CATCH(FuncName, ExceptionConstructor) \ 00067 inline void FuncName () {\ 00068 throw ExceptionConstructor (); \ 00069 } 00070 //Example of the usage 00071 00072 // void DTC_NotFound () { 00073 // throw (SALOME_DataTypeCatalog::NotFound()); 00074 // } 00075 // or the same : 00076 // 00077 // UNEXPECT_CATCH( DTC_NotFound , SALOME_DataTypeCatalog::NotFound) 00078 // in the function body : 00079 // .... 00080 // Unexpect aCatch(DTC_NotFound) // redefinition of the unexpect exceptions handler 00081 // .... 00082 00083 00084 //Definitions : 00085 UTILS_EXPORT extern void SalomeException(); 00086 UTILS_EXPORT extern void SALOME_SalomeException(); 00087 00088 #endif