Base: Add PropertyError exception
This commit is contained in:
@@ -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<Base::UnitsMismatchError>;
|
||||
new Base::ExceptionProducer<Base::CADKernelError>;
|
||||
new Base::ExceptionProducer<Base::RestoreError>;
|
||||
new Base::ExceptionProducer<Base::PropertyError>;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user