SALOME - SMESH
|
00001 // KERNEL Utils : common utils for KERNEL 00002 // Copyright (C) 2003 CEA 00003 // 00004 // This library is free software; you can redistribute it and/or 00005 // modify it under the terms of the GNU Lesser General Public 00006 // License as published by the Free Software Foundation; either 00007 // version 2.1 of the License. 00008 // 00009 00010 // This library is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 // Lesser General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU Lesser General Public 00016 // License along with this library; if not, write to the Free Software 00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 // 00019 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com 00020 // 00021 // 00022 // 00023 // File : SMESH_ExceptHandlers.hxx 00024 // Author : Oksana Tchebanova 00025 // Module : KERNEL 00026 // $Header: 00027 00028 00029 #ifndef SMESH_ExceptHandlers_HeaderFile 00030 #define SMESH_ExceptHandlers_HeaderFile 00031 00032 #include <stdexcept> 00033 00034 #include <SMESH_SMESH.hxx> 00035 00036 typedef void (*PVF)(); 00037 00038 class SMESH_EXPORT Unexpect { //save / retrieve unexpected exceptions treatment 00039 PVF old; 00040 public : 00041 #ifndef WNT 00042 Unexpect( PVF f ) 00043 { old = std::set_unexpected(f); } 00044 ~Unexpect() { std::set_unexpected(old); } 00045 #else 00046 Unexpect( PVF f ) 00047 { old = std::set_unexpected(f); } 00048 ~Unexpect() { std::set_unexpected(old); } 00049 #endif 00050 }; 00051 00052 class SMESH_EXPORT Terminate {//save / retrieve terminate function 00053 00054 PVF old; 00055 public : 00056 #ifndef WNT 00057 Terminate( PVF f ) 00058 { old = std::set_terminate(f); } 00059 ~Terminate() { std::set_terminate(old); } 00060 #else 00061 Terminate( PVF f ) 00062 { old = std::set_terminate(f); } 00063 ~Terminate() { std::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 (SMESH_DataTypeCatalog::NotFound()); 00075 // } 00076 // or the same : 00077 // 00078 // UNEXPECT_CATCH( DTC_NotFound , SMESH_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 SMESH_EXPORT void SmeshException (); 00087 #endif