Py: replace BaseExceptionFreeCADError with more suitable exception types
This commit is contained in:
@@ -166,7 +166,7 @@ AppExport std::map<std::string,std::string> Application::mConfig;
|
||||
|
||||
// Custom Python exception types
|
||||
BaseExport extern PyObject* Base::BaseExceptionFreeCADError;
|
||||
BaseExport extern PyObject* Base::BaseExceptionFreeCADAbort;
|
||||
BaseExport extern PyObject* Base::PyExc_FC_FreeCADAbort;
|
||||
BaseExport extern PyObject* Base::PyExc_FC_XMLBaseException;
|
||||
BaseExport extern PyObject* Base::PyExc_FC_XMLParseException;
|
||||
BaseExport extern PyObject* Base::PyExc_FC_XMLAttributeError;
|
||||
@@ -365,9 +365,9 @@ void Application::setupPythonException(PyObject* module)
|
||||
Py_INCREF(Base::BaseExceptionFreeCADError);
|
||||
PyModule_AddObject(module, "FreeCADError", Base::BaseExceptionFreeCADError);
|
||||
|
||||
Base::BaseExceptionFreeCADAbort = PyErr_NewException("Base.FreeCADAbort", PyExc_BaseException, nullptr);
|
||||
Py_INCREF(Base::BaseExceptionFreeCADAbort);
|
||||
PyModule_AddObject(module, "FreeCADAbort", Base::BaseExceptionFreeCADAbort);
|
||||
Base::PyExc_FC_FreeCADAbort = PyErr_NewException("Base.FreeCADAbort", PyExc_BaseException, nullptr);
|
||||
Py_INCREF(Base::PyExc_FC_FreeCADAbort);
|
||||
PyModule_AddObject(module, "FreeCADAbort", Base::PyExc_FC_FreeCADAbort);
|
||||
|
||||
Base::PyExc_FC_XMLBaseException = PyErr_NewException("Base.XMLBaseException", PyExc_Exception, nullptr);
|
||||
Py_INCREF(Base::PyExc_FC_XMLBaseException);
|
||||
|
||||
@@ -180,7 +180,7 @@ PyMethodDef Application::Methods[] = {
|
||||
"This only works if there is an active sequencer (or ProgressIndicator in Python).\n"
|
||||
"There is an active sequencer during document restore and recomputation. User may\n"
|
||||
"abort the operation by pressing the ESC key. Once detected, this function will\n"
|
||||
"trigger a BaseExceptionFreeCADAbort exception."},
|
||||
"trigger a Base.FreeCADAbort exception."},
|
||||
{NULL, NULL, 0, NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
@@ -292,7 +292,7 @@ PyObject* Application::sSetActiveDocument(PyObject * /*self*/, PyObject *args)
|
||||
GetApplication().setActiveDocument(pstr);
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
PyErr_SetString(Base::BaseExceptionFreeCADError, e.what());
|
||||
e.setPyException();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -234,7 +234,7 @@ PyObject* DocumentPy::addObject(PyObject *args, PyObject *kwd)
|
||||
if (!pcFtr) {
|
||||
std::stringstream str;
|
||||
str << "No document object found of type '" << sType << "'" << std::ends;
|
||||
throw Py::Exception(Base::BaseExceptionFreeCADError,str.str());
|
||||
throw Py::TypeError(str.str());
|
||||
}
|
||||
// Allows to hide the handling with Proxy in client python code
|
||||
if (obj) {
|
||||
@@ -300,7 +300,7 @@ PyObject* DocumentPy::removeObject(PyObject *args)
|
||||
else {
|
||||
std::stringstream str;
|
||||
str << "No document object found with name '" << sName << "'" << std::ends;
|
||||
throw Py::Exception(Base::BaseExceptionFreeCADError,str.str());
|
||||
throw Py::ValueError(str.str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -399,7 +399,7 @@ PyObject* DocumentPy::moveObject(PyObject *args)
|
||||
}
|
||||
else {
|
||||
std::string str("Failed to move the object");
|
||||
throw Py::Exception(Base::BaseExceptionFreeCADError,str);
|
||||
throw Py::ValueError(str);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -183,7 +183,7 @@ PyObject* ExtensionContainerPy::hasExtension(PyObject *args) {
|
||||
if (extension.isBad() || !extension.isDerivedFrom(App::Extension::getExtensionClassTypeId())) {
|
||||
std::stringstream str;
|
||||
str << "No extension found of type '" << type << "'" << std::ends;
|
||||
throw Py::Exception(Base::BaseExceptionFreeCADError,str.str());
|
||||
throw Py::TypeError(str.str());
|
||||
}
|
||||
|
||||
bool val = false;
|
||||
@@ -212,7 +212,7 @@ PyObject* ExtensionContainerPy::addExtension(PyObject *args) {
|
||||
if (extension.isBad() || !extension.isDerivedFrom(App::Extension::getExtensionClassTypeId())) {
|
||||
std::stringstream str;
|
||||
str << "No extension found of type '" << typeId << "'" << std::ends;
|
||||
throw Py::Exception(Base::BaseExceptionFreeCADError,str.str());
|
||||
throw Py::TypeError(str.str());
|
||||
}
|
||||
|
||||
//register the extension
|
||||
@@ -222,7 +222,7 @@ PyObject* ExtensionContainerPy::addExtension(PyObject *args) {
|
||||
delete ext;
|
||||
std::stringstream str;
|
||||
str << "Extension is not a python addable version: '" << typeId << "'" << std::ends;
|
||||
throw Py::Exception(Base::BaseExceptionFreeCADError,str.str());
|
||||
throw Py::TypeError(str.str());
|
||||
}
|
||||
|
||||
GetApplication().signalBeforeAddingDynamicExtension(*getExtensionContainerPtr(), typeId);
|
||||
|
||||
@@ -50,7 +50,7 @@ PyObject* GroupExtensionPy::newObject(PyObject *args)
|
||||
return object->getPyObject();
|
||||
}
|
||||
else {
|
||||
PyErr_Format(Base::BaseExceptionFreeCADError, "Cannot create object of type '%s'", sType);
|
||||
PyErr_Format(PyExc_TypeError, "Cannot create object of type '%s'", sType);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user