diff --git a/src/Base/PyObjectBase.h b/src/Base/PyObjectBase.h index c916703c93fe..b54dfe72de6c 100644 --- a/src/Base/PyObjectBase.h +++ b/src/Base/PyObjectBase.h @@ -471,12 +471,10 @@ BaseExport extern PyObject* PyExc_FC_AbortIOException; #define PY_TRY try #define __PY_CATCH(R) \ - catch(Base::Exception &e) \ + catch(const Base::Exception &e) \ { \ - auto pye = e.getPyExceptionType(); \ - if(!pye) \ - pye = Base::PyExc_FC_GeneralError; \ - _Py_ErrorObj(R,pye,e.getPyObject()); \ + e.setPyException(); \ + R; \ } \ catch(const std::exception &e) \ { \ diff --git a/src/Tools/generateTemplates/templateClassPyExport.py b/src/Tools/generateTemplates/templateClassPyExport.py index 885d889bae26..4d0dd5ff3b9c 100644 --- a/src/Tools/generateTemplates/templateClassPyExport.py +++ b/src/Tools/generateTemplates/templateClassPyExport.py @@ -622,15 +622,12 @@ class @self.export.Namespace.replace("::","_")@Export @self.export.Name@ : publi - return ret; } // Please sync the following catch implementation with PY_CATCH - catch(Base::Exception &e) + catch(const Base::Exception& e) { - auto pye = e.getPyExceptionType(); - if(!pye) - pye = Base::PyExc_FC_GeneralError; - PyErr_SetObject(pye, e.getPyObject()); + e.setPyException(); return nullptr; } - catch(const std::exception &e) + catch(const std::exception& e) { PyErr_SetString(Base::PyExc_FC_GeneralError, e.what()); return nullptr; @@ -785,15 +782,12 @@ class @self.export.Namespace.replace("::","_")@Export @self.export.Name@ : publi PyObject *r = getCustomAttributes(attr); if(r) return r; } // Please sync the following catch implementation with PY_CATCH - catch(Base::Exception &e) + catch(const Base::Exception& e) { - auto pye = e.getPyExceptionType(); - if(!pye) - pye = Base::PyExc_FC_GeneralError; - PyErr_SetObject(pye, e.getPyObject()); + e.setPyException(); return nullptr; } - catch(const std::exception &e) + catch(const std::exception& e) { PyErr_SetString(Base::PyExc_FC_GeneralError, e.what()); return nullptr; @@ -835,15 +829,12 @@ class @self.export.Namespace.replace("::","_")@Export @self.export.Name@ : publi else if (r == -1) return -1; } // Please sync the following catch implementation with PY_CATCH - catch(Base::Exception &e) + catch(const Base::Exception& e) { - auto pye = e.getPyExceptionType(); - if(!pye) - pye = Base::PyExc_FC_GeneralError; - PyErr_SetObject(pye, e.getPyObject()); + e.setPyException(); return -1; } - catch(const std::exception &e) + catch(const std::exception& e) { PyErr_SetString(Base::PyExc_FC_GeneralError, e.what()); return -1;