Back to index

salome-kernel  6.5.0
Utils_ExceptHandlers.hxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  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 
00023 //  KERNEL Utils : common utils for KERNEL
00024 //  File   : Utils_ExceptHandlers.hxx
00025 //  Author : Oksana Tchebanova
00026 //  Module : KERNEL
00027 //  $Header:
00028 //
00029 #ifndef Utils_ExceptHandlers_HeaderFile
00030 #define Utils_ExceptHandlers_HeaderFile
00031 
00032 #include "SALOME_Utils.hxx"
00033 
00034 #include <stdexcept>
00035 
00036 typedef void (*PVF)();
00037 
00038 class UTILS_EXPORT Unexpect { //save / retrieve unexpected exceptions treatment
00039   PVF old;
00040   public :
00041 #ifndef WIN32
00042     Unexpect( PVF f ) 
00043       { old = std::set_unexpected(f); }
00044   ~Unexpect() { std::set_unexpected(old); }
00045 #else
00046     Unexpect( PVF f ) 
00047       { old = ::set_unexpected(f); }
00048   ~Unexpect() { ::set_unexpected(old); }
00049 #endif
00050 };
00051 
00052 class UTILS_EXPORT Terminate {//save / retrieve terminate function
00053   
00054   PVF old;
00055   public :
00056 #ifndef WIN32
00057     Terminate( PVF f ) 
00058       { old = std::set_terminate(f); }
00059   ~Terminate() { std::set_terminate(old); }
00060 #else
00061     Terminate( PVF f ) 
00062       { old = ::set_terminate(f); }
00063   ~Terminate() { ::set_terminate(old); }
00064 #endif
00065 };
00066 
00067 #define UNEXPECT_CATCH(FuncName, ExceptionConstructor) \
00068 inline void FuncName () {\
00069    throw ExceptionConstructor (); \
00070 }
00071 //Example of the usage 
00072 
00073 // void DTC_NotFound () {
00074 //   throw (SALOME_DataTypeCatalog::NotFound());
00075 // }
00076 // or the same :
00077 //
00078 // UNEXPECT_CATCH( DTC_NotFound , SALOME_DataTypeCatalog::NotFound)
00079 // in the function body :
00080 // ....
00081 // Unexpect aCatch(DTC_NotFound) // redefinition of the unexpect exceptions handler
00082 // ....
00083 
00084 
00085 //Definitions :
00086 UTILS_EXPORT extern void SalomeException();
00087 UTILS_EXPORT extern void SALOME_SalomeException();
00088 
00089 #endif