diff --git a/src/App/Application.cpp b/src/App/Application.cpp index 61291c85bd..624ec2c7c6 100644 --- a/src/App/Application.cpp +++ b/src/App/Application.cpp @@ -423,6 +423,10 @@ void Application::setupPythonException(PyObject* module) Base::PyExc_FC_CADKernelError = PyErr_NewException("Base.CADKernelError", Base::PyExc_FC_GeneralError, nullptr); Py_INCREF(Base::PyExc_FC_CADKernelError); PyModule_AddObject(module, "CADKernelError", Base::PyExc_FC_CADKernelError); + + Base::PyExc_FC_PropertyError = PyErr_NewException("Base.PropertyError", PyExc_AttributeError, nullptr); + Py_INCREF(Base::PyExc_FC_PropertyError); + PyModule_AddObject(module, "PropertyError", Base::PyExc_FC_PropertyError); } // clang-format on @@ -2184,6 +2188,7 @@ void Application::initTypes() new Base::ExceptionProducer; new Base::ExceptionProducer; new Base::ExceptionProducer; + new Base::ExceptionProducer; } namespace { diff --git a/src/App/PropertyContainerPyImp.cpp b/src/App/PropertyContainerPyImp.cpp index 28446c0eeb..8e2196dbbf 100644 --- a/src/App/PropertyContainerPyImp.cpp +++ b/src/App/PropertyContainerPyImp.cpp @@ -63,7 +63,7 @@ PyObject* PropertyContainerPy::getPropertyByName(PyObject *args) App::Property* prop = getPropertyContainerPtr()->getPropertyByName(pstr); if (!prop) { - PyErr_Format(PyExc_AttributeError, "Property container has no property '%s'", pstr); + PyErr_Format(Base::PyExc_FC_PropertyError, "Property container has no property '%s'", pstr); return nullptr; } diff --git a/src/Base/Exception.cpp b/src/Base/Exception.cpp index 6de4007eec..acbf6aa16c 100644 --- a/src/Base/Exception.cpp +++ b/src/Base/Exception.cpp @@ -612,6 +612,23 @@ PyObject* AttributeError::getPyExceptionType() const // --------------------------------------------------------- +PropertyError::PropertyError() = default; + +PropertyError::PropertyError(const char* sMessage) + : AttributeError(sMessage) +{} + +PropertyError::PropertyError(const std::string& sMessage) + : AttributeError(sMessage) +{} + +PyObject* PropertyError::getPyExceptionType() const +{ + return PyExc_FC_PropertyError; +} + +// --------------------------------------------------------- + RuntimeError::RuntimeError() = default; RuntimeError::RuntimeError(const char* sMessage) diff --git a/src/Base/Exception.h b/src/Base/Exception.h index 77e9545f84..2ebdd78744 100644 --- a/src/Base/Exception.h +++ b/src/Base/Exception.h @@ -670,6 +670,26 @@ public: PyObject* getPyExceptionType() const override; }; +/** + * The PropertyError can be used to indicate the usage of a wrong property name or value. + * @author Mario Passaglia + */ +class BaseExport PropertyError: public AttributeError +{ +public: + /// Construction + PropertyError(); + explicit PropertyError(const char* sMessage); + explicit PropertyError(const std::string& sMessage); + PropertyError(const PropertyError&) = default; + PropertyError(PropertyError&&) = default; + /// Destruction + ~PropertyError() noexcept override = default; + PropertyError& operator=(const PropertyError&) = default; + PropertyError& operator=(PropertyError&&) = default; + PyObject* getPyExceptionType() const override; +}; + /** * The RuntimeError can be used to indicate an unknown exception at runtime. * @author Werner Mayer diff --git a/src/Base/PyObjectBase.cpp b/src/Base/PyObjectBase.cpp index be96008764..45c62c8f27 100644 --- a/src/Base/PyObjectBase.cpp +++ b/src/Base/PyObjectBase.cpp @@ -48,6 +48,7 @@ PyObject* Base::PyExc_FC_BadGraphError = nullptr; PyObject* Base::PyExc_FC_ExpressionError = nullptr; PyObject* Base::PyExc_FC_ParserError = nullptr; PyObject* Base::PyExc_FC_CADKernelError = nullptr; +PyObject* Base::PyExc_FC_PropertyError = nullptr; typedef struct { //NOLINT PyObject_HEAD diff --git a/src/Base/PyObjectBase.h b/src/Base/PyObjectBase.h index 5f1ac2a7ed..2f40a24a61 100644 --- a/src/Base/PyObjectBase.h +++ b/src/Base/PyObjectBase.h @@ -430,6 +430,7 @@ BaseExport extern PyObject* PyExc_FC_BadGraphError; BaseExport extern PyObject* PyExc_FC_ExpressionError; BaseExport extern PyObject* PyExc_FC_ParserError; BaseExport extern PyObject* PyExc_FC_CADKernelError; +BaseExport extern PyObject* PyExc_FC_PropertyError; /** Exception handling for python callback functions * Is a convenience macro to manage the exception handling of python callback