diff --git a/src/Base/PyObjectBase.h b/src/Base/PyObjectBase.h index ea45d848f0..6c52c67d86 100644 --- a/src/Base/PyObjectBase.h +++ b/src/Base/PyObjectBase.h @@ -446,12 +446,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/bindings/templates/templateClassPyExport.py b/src/Tools/bindings/templates/templateClassPyExport.py index cea916559e..99811a2aa4 100644 --- a/src/Tools/bindings/templates/templateClassPyExport.py +++ b/src/Tools/bindings/templates/templateClassPyExport.py @@ -669,15 +669,12 @@ PyObject * @self.export.Name@::staticCallback_@i.Name@ (PyObject *self, PyObject - 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; @@ -832,15 +829,12 @@ PyObject *@self.export.Name@::_getattr(const char *attr) // __getattr__ functi 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; @@ -882,15 +876,12 @@ int @self.export.Name@::_setattr(const char *attr, PyObject *value) // __setattr 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;