/*************************************************************************** * Copyright (c) Sebastian Hoogen (github@sebastianhoogen.de) 2014 * * * * This file is part of the FreeCAD CAx development system. * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Library General Public * * License as published by the Free Software Foundation; either * * version 2 of the License, or (at your option) any later version. * * * * 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 Library General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this library; see the file COPYING.LIB. If not, * * write to the Free Software Foundation, Inc., 59 Temple Place, * * Suite 330, Boston, MA 02111-1307, USA * * * ***************************************************************************/ #ifndef _OCCError_h_ #define _OCCError_h_ # include # include # include # include # if OCC_VERSION_HEX >= 0x060500 # include # endif # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include #include #include #include #include #include namespace Part { PartExport extern PyObject* PartExceptionOCCError; PartExport extern PyObject* PartExceptionOCCDomainError; PartExport extern PyObject* PartExceptionOCCRangeError; PartExport extern PyObject* PartExceptionOCCConstructionError; PartExport extern PyObject* PartExceptionOCCDimensionError; #define PY_TRY try #ifndef DONT_CATCH_CXX_EXCEPTIONS /// see docu of PY_TRY # define PY_CATCH_OCC catch (Standard_Failure &e) \ { \ std::string str; \ Standard_CString msg = e.GetMessageString(); \ str += typeid(e).name(); \ str += " "; \ if (msg) {str += msg;} \ else {str += "No OCCT Exception Message";} \ Base::Console().Error(str.c_str()); \ Py_Error(Part::PartExceptionOCCError,str.c_str()); \ } \ catch(Base::Exception &e) \ { \ std::string str; \ str += "FreeCAD exception thrown ("; \ str += e.what(); \ str += ")"; \ e.ReportException(); \ Py_Error(Base::BaseExceptionFreeCADError,str.c_str()); \ } \ catch(std::exception &e) \ { \ std::string str; \ str += "STL exception thrown ("; \ str += e.what(); \ str += ")"; \ Base::Console().Error(str.c_str()); \ Py_Error(Base::BaseExceptionFreeCADError,str.c_str()); \ } \ catch(const Py::Exception&) \ { \ return NULL; \ } \ catch(const char *e) \ { \ Py_Error(Base::BaseExceptionFreeCADError,e); \ } \ catch(...) \ { \ Py_Error(Base::BaseExceptionFreeCADError,"Unknown C++ exception"); \ } #else /// see docu of PY_TRY # define PY_CATCH_OCC catch (Standard_Failure &e) \ { \ std::string str; \ Standard_CString msg = e.GetMessageString(); \ str += typeid(e).name(); \ str += " "; \ if (msg) {str += msg;} \ else {str += "No OCCT Exception Message";} \ Base::Console().Error(str.c_str()); \ Py_Error(Part::PartExceptionOCCError,str.c_str()); \ } \ catch(Base::Exception &e) \ { \ std::string str; \ str += "FreeCAD exception thrown ("; \ str += e.what(); \ str += ")"; \ e.ReportException(); \ Py_Error(Base::BaseExceptionFreeCADError,str.c_str()); \ } \ catch(std::exception &e) \ { \ std::string str; \ str += "STL exception thrown ("; \ str += e.what(); \ str += ")"; \ Base::Console().Error(str.c_str()); \ Py_Error(Base::BaseExceptionFreeCADError,str.c_str()); \ } \ catch(const Py::Exception&) \ { \ return NULL; \ } \ catch(const char *e) \ { \ Py_Error(Base::BaseExceptionFreeCADError,e); \ } #endif // DONT_CATCH_CXX_EXCEPTIONS } //namespace Part #endif // _OCCError_h_