fixes #0001422: Subclass Exception

inherit Base.FreeCADError form RuntimeError
inherit Part.OCCError from Base.FreeCADError
inherit OCCDomainError from Part.OCCError
inherit OCCRangeError from Part.OCCError
inherit OCCConstructionError from OCCDomainError
inherit OCCDimensionError from OCCDomainError
Added PY_CATCH_OCC macro
replace PyExc_Exception
use FreeCADError in makeWireString
catch exception in BSplineCurve.increasedegree
This commit is contained in:
Sebastian Hoogen
2014-08-19 11:18:19 +02:00
committed by wmayer
parent 6cd1feb44f
commit af50cbf964
69 changed files with 749 additions and 501 deletions

View File

@@ -78,7 +78,7 @@ int AxisPy::PyInit(PyObject* args, PyObject* /*kwd*/)
return 0;
}
PyErr_SetString(PyExc_Exception, "empty parameter list, axis or base and direction expected");
PyErr_SetString(Base::BaseExceptionFreeCADError, "empty parameter list, axis or base and direction expected");
return -1;
}

View File

@@ -196,7 +196,7 @@ PyObject* BoundBoxPy::getIntersectionPoint(PyObject *args)
return new VectorPy(point);
}
else {
PyErr_SetString(PyExc_Exception, "No intersection");
PyErr_SetString(Base::BaseExceptionFreeCADError, "No intersection");
return 0;
}
}

View File

@@ -85,7 +85,7 @@ int MatrixPy::PyInit(PyObject* args, PyObject* /*kwd*/)
return 0;
}
PyErr_SetString(PyExc_Exception, "matrix or up to 16 floats expected");
PyErr_SetString(Base::BaseExceptionFreeCADError, "matrix or up to 16 floats expected");
return -1;
}
@@ -331,7 +331,7 @@ PyObject* MatrixPy::multiply(PyObject * args)
return new VectorPy(new Vector3d(vec));
}
PyErr_SetString(PyExc_Exception, "either vector or matrix expected");
PyErr_SetString(Base::BaseExceptionFreeCADError, "either vector or matrix expected");
return 0;
}
@@ -344,7 +344,7 @@ PyObject* MatrixPy::invert(PyObject * args)
if (fabs(getMatrixPtr()->determinant()) > DBL_EPSILON)
getMatrixPtr()->inverseGauss();
else {
PyErr_SetString(PyExc_Exception, "Cannot invert singular matrix");
PyErr_SetString(Base::BaseExceptionFreeCADError, "Cannot invert singular matrix");
return 0;
}
}
@@ -365,7 +365,7 @@ PyObject* MatrixPy::inverse(PyObject * args)
return new MatrixPy(m);
}
else {
PyErr_SetString(PyExc_Exception, "Cannot invert singular matrix");
PyErr_SetString(Base::BaseExceptionFreeCADError, "Cannot invert singular matrix");
return 0;
}
}

View File

@@ -114,7 +114,7 @@ int PlacementPy::PyInit(PyObject* args, PyObject* /*kwd*/)
return 0;
}
PyErr_SetString(PyExc_Exception, "empty parameter list, matrix or placement expected");
PyErr_SetString(Base::BaseExceptionFreeCADError, "empty parameter list, matrix or placement expected");
return -1;
}

View File

@@ -33,6 +33,8 @@
using namespace Base;
PyObject* Base::BaseExceptionFreeCADError = 0;
// Constructor
PyObjectBase::PyObjectBase(void* p,PyTypeObject *T)
: _pcTwinPointer(p), parent(0), attribute(0)

View File

@@ -377,6 +377,9 @@ static PyObject * s##DFUNC (PyObject *self, PyObject *args, PyObject * /*kwd*/){
*/
#define PYMETHODEDEF(FUNC) {"" #FUNC "",(PyCFunction) s##FUNC,Py_NEWARGS},
BaseExport extern PyObject* BaseExceptionFreeCADError;
#define PY_FCERROR (Base::BaseExceptionFreeCADError ? \
BaseExceptionFreeCADError : PyExc_RuntimeError)
/** Exception handling for python callback functions
@@ -427,7 +430,7 @@ static PyObject * s##DFUNC (PyObject *self, PyObject *args, PyObject * /*kwd*/){
str += e.what(); \
str += ")"; \
e.ReportException(); \
Py_Error(PyExc_Exception,str.c_str()); \
Py_Error(Base::BaseExceptionFreeCADError,str.c_str()); \
} \
catch(std::exception &e) \
{ \
@@ -436,7 +439,7 @@ static PyObject * s##DFUNC (PyObject *self, PyObject *args, PyObject * /*kwd*/){
str += e.what(); \
str += ")"; \
Base::Console().Error(str.c_str()); \
Py_Error(PyExc_Exception,str.c_str()); \
Py_Error(Base::BaseExceptionFreeCADError,str.c_str()); \
} \
catch(const Py::Exception&) \
{ \
@@ -444,11 +447,11 @@ static PyObject * s##DFUNC (PyObject *self, PyObject *args, PyObject * /*kwd*/){
} \
catch(const char *e) \
{ \
Py_Error(PyExc_Exception,e); \
Py_Error(Base::BaseExceptionFreeCADError,e); \
} \
catch(...) \
{ \
Py_Error(PyExc_Exception,"Unknown C++ exception"); \
Py_Error(Base::BaseExceptionFreeCADError,"Unknown C++ exception"); \
}
#else
@@ -460,7 +463,7 @@ static PyObject * s##DFUNC (PyObject *self, PyObject *args, PyObject * /*kwd*/){
str += e.what(); \
str += ")"; \
e.ReportException(); \
Py_Error(PyExc_Exception,str.c_str()); \
Py_Error(Base::BaseExceptionFreeCADError,str.c_str()); \
} \
catch(std::exception &e) \
{ \
@@ -469,7 +472,7 @@ static PyObject * s##DFUNC (PyObject *self, PyObject *args, PyObject * /*kwd*/){
str += e.what(); \
str += ")"; \
Base::Console().Error(str.c_str()); \
Py_Error(PyExc_Exception,str.c_str()); \
Py_Error(Base::BaseExceptionFreeCADError,str.c_str()); \
} \
catch(const Py::Exception&) \
{ \
@@ -477,7 +480,7 @@ static PyObject * s##DFUNC (PyObject *self, PyObject *args, PyObject * /*kwd*/){
} \
catch(const char *e) \
{ \
Py_Error(PyExc_Exception,e); \
Py_Error(Base::BaseExceptionFreeCADError,e); \
}
#endif // DONT_CATCH_CXX_EXCEPTIONS

View File

@@ -334,7 +334,7 @@ PyObject* VectorPy::normalize(PyObject *args)
return 0;
VectorPy::PointerType ptr = reinterpret_cast<VectorPy::PointerType>(_pcTwinPointer);
if (ptr->Length() < 1.0e-6) {
PyErr_SetString(PyExc_Exception, "Cannot normalize null vector");
PyErr_SetString(Base::BaseExceptionFreeCADError, "Cannot normalize null vector");
return 0;
}