Py: replace BaseExceptionFreeCADError with more suitable exception types

This commit is contained in:
wmayer
2022-03-17 13:54:23 +01:00
parent 18847444d4
commit 1f12dca2b4
38 changed files with 148 additions and 133 deletions

View File

@@ -274,7 +274,7 @@ private:
} else {
std::string exStr("Can't determine mesh format from file name: '");
exStr += outputFileName + "'";
throw Py::Exception(Base::BaseExceptionFreeCADError, exStr.c_str());
throw Py::ValueError(exStr.c_str());
}
for (auto it : objectList) {
@@ -335,7 +335,7 @@ private:
}
while (false);
if (!mesh) {
throw Py::Exception(Base::BaseExceptionFreeCADError, "Creation of box failed");
throw Py::RuntimeError("Creation of box failed");
}
return Py::asObject(new MeshPy(mesh));
}
@@ -368,7 +368,7 @@ private:
MeshObject* mesh = MeshObject::createSphere(radius, sampling);
if (!mesh) {
throw Py::Exception(Base::BaseExceptionFreeCADError, "Creation of sphere failed");
throw Py::RuntimeError("Creation of sphere failed");
}
return Py::asObject(new MeshPy(mesh));
}
@@ -382,7 +382,7 @@ private:
MeshObject* mesh = MeshObject::createEllipsoid(radius1, radius2, sampling);
if (!mesh) {
throw Py::Exception(Base::BaseExceptionFreeCADError, "Creation of ellipsoid failed");
throw Py::RuntimeError("Creation of ellipsoid failed");
}
return Py::asObject(new MeshPy(mesh));
}
@@ -398,7 +398,7 @@ private:
MeshObject* mesh = MeshObject::createCylinder(radius, length, closed, edgelen, sampling);
if (!mesh) {
throw Py::Exception(Base::BaseExceptionFreeCADError, "Creation of cylinder failed");
throw Py::RuntimeError("Creation of cylinder failed");
}
return Py::asObject(new MeshPy(mesh));
}
@@ -415,7 +415,7 @@ private:
MeshObject* mesh = MeshObject::createCone(radius1, radius2, len, closed, edgelen, sampling);
if (!mesh) {
throw Py::Exception(Base::BaseExceptionFreeCADError, "Creation of cone failed");
throw Py::RuntimeError("Creation of cone failed");
}
return Py::asObject(new MeshPy(mesh));
}
@@ -429,7 +429,7 @@ private:
MeshObject* mesh = MeshObject::createTorus(radius1, radius2, sampling);
if (!mesh) {
throw Py::Exception(Base::BaseExceptionFreeCADError, "Creation of torus failed");
throw Py::RuntimeError("Creation of torus failed");
}
return Py::asObject(new MeshPy(mesh));
}

View File

@@ -180,7 +180,7 @@ PyObject* MeshFeaturePy::fixSelfIntersections(PyObject *args)
obj->Mesh.finishEditing();
}
catch (const Base::Exception& e) {
PyErr_SetString(Base::BaseExceptionFreeCADError, e.what());
e.setPyException();
return nullptr;
}
Py_Return;
@@ -197,7 +197,7 @@ PyObject* MeshFeaturePy::removeFoldsOnSurface(PyObject *args)
obj->Mesh.finishEditing();
}
catch (const Base::Exception& e) {
PyErr_SetString(Base::BaseExceptionFreeCADError, e.what());
e.setPyException();
return nullptr;
}
Py_Return;
@@ -214,7 +214,7 @@ PyObject* MeshFeaturePy::removeInvalidPoints(PyObject *args)
obj->Mesh.finishEditing();
}
catch (const Base::Exception& e) {
PyErr_SetString(Base::BaseExceptionFreeCADError, e.what());
e.setPyException();
return nullptr;
}
Py_Return;

View File

@@ -98,7 +98,7 @@ int MeshPy::PyInit(PyObject* args, PyObject*)
}
}
catch (const Base::Exception &e) {
PyErr_SetString(Base::BaseExceptionFreeCADError,e.what());
e.setPyException();
return -1;
}
catch (const std::exception &e) {
@@ -643,7 +643,7 @@ PyObject* MeshPy::addFacet(PyObject *args)
Py_Return;
}
PyErr_SetString(Base::BaseExceptionFreeCADError, "set 9 floats or three vectors or a facet");
PyErr_SetString(PyExc_TypeError, "set 9 floats or three vectors or a facet");
return nullptr;
}
@@ -690,7 +690,7 @@ PyObject* MeshPy::addFacets(PyObject *args)
}
}
else {
PyErr_SetString(Base::BaseExceptionFreeCADError, "expect a sequence of floats or Vector");
PyErr_SetString(PyExc_TypeError, "expect a sequence of floats or Vector");
return nullptr;
}
@@ -746,7 +746,7 @@ PyObject* MeshPy::addFacets(PyObject *args)
Py_Return;
}
PyErr_SetString(Base::BaseExceptionFreeCADError, "either expect\n"
PyErr_SetString(PyExc_TypeError, "either expect\n"
"-- [Vector] (3 of them define a facet)\n"
"-- ([Vector],[(int,int,int)])");
return nullptr;
@@ -1069,7 +1069,7 @@ PyObject* MeshPy::fixSelfIntersections(PyObject *args)
getMeshObjectPtr()->removeSelfIntersections();
}
catch (const Base::Exception& e) {
PyErr_SetString(Base::BaseExceptionFreeCADError, e.what());
e.setPyException();
return nullptr;
}
Py_Return;
@@ -1083,7 +1083,7 @@ PyObject* MeshPy::removeFoldsOnSurface(PyObject *args)
getMeshObjectPtr()->removeFoldsOnSurface();
}
catch (const Base::Exception& e) {
PyErr_SetString(Base::BaseExceptionFreeCADError, e.what());
e.setPyException();
return nullptr;
}
Py_Return;
@@ -1105,7 +1105,7 @@ PyObject* MeshPy::removeInvalidPoints(PyObject *args)
getMeshObjectPtr()->removeInvalidPoints();
}
catch (const Base::Exception& e) {
PyErr_SetString(Base::BaseExceptionFreeCADError, e.what());
e.setPyException();
return nullptr;
}
Py_Return;
@@ -1129,7 +1129,7 @@ PyObject* MeshPy::removePointsOnEdge(PyObject *args, PyObject *kwds)
getMeshObjectPtr()->removePointsOnEdge(PyObject_IsTrue(fillBoundary) ? true : false);
}
catch (const Base::Exception& e) {
PyErr_SetString(Base::BaseExceptionFreeCADError, e.what());
e.setPyException();
return nullptr;
}
Py_Return;
@@ -1240,7 +1240,7 @@ PyObject* MeshPy::fillupHoles(PyObject *args)
getMeshObjectPtr()->fillupHoles(len, level, *tria);
}
catch (const Base::Exception& e) {
PyErr_SetString(Base::BaseExceptionFreeCADError, e.what());
e.setPyException();
return nullptr;
}