diff --git a/src/Base/PlacementPyImp.cpp b/src/Base/PlacementPyImp.cpp index fa6d77031c..1640cc9cd1 100644 --- a/src/Base/PlacementPyImp.cpp +++ b/src/Base/PlacementPyImp.cpp @@ -67,9 +67,15 @@ int PlacementPy::PyInit(PyObject* args, PyObject* /*kwd*/) PyErr_Clear(); if (PyArg_ParseTuple(args, "O!", &(Base::MatrixPy::Type), &o)) { - Base::Matrix4D mat = static_cast(o)->value(); - getPlacementPtr()->fromMatrix(mat); - return 0; + try { + Base::Matrix4D mat = static_cast(o)->value(); + getPlacementPtr()->fromMatrix(mat); + return 0; + } + catch (const Base::Exception& e) { + PyErr_SetString(e.getPyExceptionType(), e.what()); + return -1; + } } PyErr_Clear(); @@ -342,8 +348,13 @@ void PlacementPy::setMatrix(Py::Object arg) Py::Matrix mat; if (!mat.accepts(arg.ptr())) throw Py::TypeError("Expect type Matrix"); - mat = arg; - getPlacementPtr()->fromMatrix(mat); + try { + mat = arg; + getPlacementPtr()->fromMatrix(mat); + } + catch (const Base::ValueError& e) { + throw Py::ValueError(e.what()); + } } PyObject *PlacementPy::getCustomAttributes(const char* attr) const diff --git a/src/Base/RotationPyImp.cpp b/src/Base/RotationPyImp.cpp index ece14131a7..6292c9b16b 100644 --- a/src/Base/RotationPyImp.cpp +++ b/src/Base/RotationPyImp.cpp @@ -92,8 +92,14 @@ int RotationPy::PyInit(PyObject* args, PyObject* kwds) PyErr_Clear(); if (PyArg_ParseTuple(args, "O!", &(Base::MatrixPy::Type), &o)) { - getRotationPtr()->setValue(static_cast(o)->value()); - return 0; + try { + getRotationPtr()->setValue(static_cast(o)->value()); + return 0; + } + catch (const Base::Exception& e) { + PyErr_SetString(e.getPyExceptionType(), e.what()); + return -1; + } } PyErr_Clear(); @@ -134,12 +140,18 @@ int RotationPy::PyInit(PyObject* args, PyObject* kwds) &a31, &a32, &a33, &a34, &a41, &a42, &a43, &a44)) { - Matrix4D mtx(a11, a12, a13, a14, - a21, a22, a23, a24, - a31, a32, a33, a34, - a41, a42, a43, a44); - getRotationPtr()->setValue(mtx); - return 0; + try { + Matrix4D mtx(a11, a12, a13, a14, + a21, a22, a23, a24, + a31, a32, a33, a34, + a41, a42, a43, a44); + getRotationPtr()->setValue(mtx); + return 0; + } + catch (const Base::Exception& e) { + PyErr_SetString(e.getPyExceptionType(), e.what()); + return -1; + } } // try read a 3x3 matrix @@ -149,15 +161,20 @@ int RotationPy::PyInit(PyObject* args, PyObject* kwds) &a21, &a22, &a23, &a31, &a32, &a33)) { - Matrix4D mtx(a11, a12, a13, a14, - a21, a22, a23, a24, - a31, a32, a33, a34, - a41, a42, a43, a44); - getRotationPtr()->setValue(mtx); - return 0; + try { + Matrix4D mtx(a11, a12, a13, a14, + a21, a22, a23, a24, + a31, a32, a33, a34, + a41, a42, a43, a44); + getRotationPtr()->setValue(mtx); + return 0; + } + catch (const Base::Exception& e) { + PyErr_SetString(e.getPyExceptionType(), e.what()); + return -1; + } } - PyErr_Clear(); PyObject *v1, *v2; if (PyArg_ParseTuple(args, "O!O!", &(Base::VectorPy::Type), &v1, @@ -485,8 +502,14 @@ int RotationPy::setCustomAttributes(const char* attr, PyObject* obj) { if (strcmp(attr, "Matrix") == 0) { if (PyObject_TypeCheck(obj, &(MatrixPy::Type))) { - this->getRotationPtr()->setValue(*static_cast(obj)->getMatrixPtr()); - return 1; + try { + this->getRotationPtr()->setValue(*static_cast(obj)->getMatrixPtr()); + return 1; + } + catch (const Base::Exception& e) { + PyErr_SetString(e.getPyExceptionType(), e.what()); + return -1; + } } } else if (strcmp(attr, "Axes") == 0) {