App: Improve Metadata error handling

Report XML parse exception details.
This commit is contained in:
Chris Hennes
2022-03-13 21:00:49 -05:00
parent 2ac4e60ab5
commit 2fc9c93235
7 changed files with 103 additions and 1 deletions

View File

@@ -29,6 +29,7 @@
#include "MetadataPy.cpp"
using namespace Base;
XERCES_CPP_NAMESPACE_USE
// Returns a string which represents the object e.g. when printed in Python
std::string MetadataPy::representation(void) const
@@ -70,6 +71,24 @@ int MetadataPy::PyInit(PyObject* args, PyObject* /*kwd*/)
setTwinPointer(md);
return 0;
}
catch (const Base::XMLBaseException& e) {
PyErr_SetString(Base::BaseExceptionFreeCADError, e.what());
return -1;
}
catch (const XMLException& toCatch) {
char* message = XMLString::transcode(toCatch.getMessage());
std::string what = message;
XMLString::release(&message);
PyErr_SetString(Base::BaseExceptionFreeCADError, what.c_str());
return -1;
}
catch (const DOMException& toCatch) {
char* message = XMLString::transcode(toCatch.getMessage());
std::string what = message;
XMLString::release(&message);
PyErr_SetString(Base::BaseExceptionFreeCADError, what.c_str());
return -1;
}
catch (...) {
PyErr_SetString(Base::BaseExceptionFreeCADError, "Failed to create Metadata object");
return -1;