Use PyErr_setObject with a PyDict to set Base::Exception information to BaseFreeCADError Python exception
This commit is contained in:
@@ -494,12 +494,19 @@ PyObject * @self.export.Name@::staticCallback_@i.Name@ (PyObject *self, PyObject
|
||||
}
|
||||
catch(const Base::Exception& e) // catch the FreeCAD exceptions
|
||||
{
|
||||
std::string str;
|
||||
str += "FreeCAD exception thrown (";
|
||||
str += e.what();
|
||||
str += ")";
|
||||
PyObject *edict = PyDict_New();
|
||||
|
||||
PyDict_SetItemString(edict, "sclassname", PyString_FromString(typeid(e).name()));
|
||||
PyDict_SetItemString(edict, "sErrMsg", PyString_FromString(e.getMessage().c_str()));
|
||||
PyDict_SetItemString(edict, "sfile", PyString_FromString(e.getFile().c_str()));
|
||||
PyDict_SetItemString(edict, "iline", PyInt_FromLong(e.getLine()));
|
||||
PyDict_SetItemString(edict, "sfunction", PyString_FromString(e.getFunction().c_str()));
|
||||
PyDict_SetItemString(edict, "swhat", PyString_FromString(e.what()));
|
||||
|
||||
e.ReportException();
|
||||
PyErr_SetString(Base::BaseExceptionFreeCADError,str.c_str());
|
||||
PyErr_SetObject(Base::BaseExceptionFreeCADError, edict);
|
||||
Py_DECREF(edict);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
catch(const boost::filesystem::filesystem_error& e) // catch boost filesystem exception
|
||||
@@ -684,12 +691,18 @@ PyObject *@self.export.Name@::_getattr(char *attr) // __getattr__ function: n
|
||||
#ifndef DONT_CATCH_CXX_EXCEPTIONS
|
||||
catch(const Base::Exception& e) // catch the FreeCAD exceptions
|
||||
{
|
||||
std::string str;
|
||||
str += "FreeCAD exception thrown (";
|
||||
str += e.what();
|
||||
str += ")";
|
||||
PyObject *edict = PyDict_New();
|
||||
|
||||
PyDict_SetItemString(edict, "sclassname", PyString_FromString(typeid(e).name()));
|
||||
PyDict_SetItemString(edict, "sErrMsg", PyString_FromString(e.getMessage().c_str()));
|
||||
PyDict_SetItemString(edict, "sfile", PyString_FromString(e.getFile().c_str()));
|
||||
PyDict_SetItemString(edict, "iline", PyInt_FromLong(e.getLine()));
|
||||
PyDict_SetItemString(edict, "sfunction", PyString_FromString(e.getFunction().c_str()));
|
||||
PyDict_SetItemString(edict, "swhat", PyString_FromString(e.what()));
|
||||
|
||||
e.ReportException();
|
||||
PyErr_SetString(Base::BaseExceptionFreeCADError,str.c_str());
|
||||
PyErr_SetObject(Base::BaseExceptionFreeCADError, edict);
|
||||
Py_DECREF(edict);
|
||||
return NULL;
|
||||
}
|
||||
catch(const std::exception& e) // catch other c++ exceptions
|
||||
@@ -715,12 +728,19 @@ PyObject *@self.export.Name@::_getattr(char *attr) // __getattr__ function: n
|
||||
#else // DONT_CATCH_CXX_EXCEPTIONS
|
||||
catch(const Base::Exception& e) // catch the FreeCAD exceptions
|
||||
{
|
||||
std::string str;
|
||||
str += "FreeCAD exception thrown (";
|
||||
str += e.what();
|
||||
str += ")";
|
||||
PyObject *edict = PyDict_New();
|
||||
|
||||
PyDict_SetItemString(edict, "sclassname", PyString_FromString(typeid(e).name()));
|
||||
PyDict_SetItemString(edict, "sErrMsg", PyString_FromString(e.getMessage().c_str()));
|
||||
PyDict_SetItemString(edict, "sfile", PyString_FromString(e.getFile().c_str()));
|
||||
PyDict_SetItemString(edict, "iline", PyInt_FromLong(e.getLine()));
|
||||
PyDict_SetItemString(edict, "sfunction", PyString_FromString(e.getFunction().c_str()));
|
||||
PyDict_SetItemString(edict, "swhat", PyString_FromString(e.what()));
|
||||
|
||||
e.ReportException();
|
||||
PyErr_SetString(Base::BaseExceptionFreeCADError,str.c_str());
|
||||
PyErr_SetObject(Base::BaseExceptionFreeCADError, edict);
|
||||
Py_DECREF(edict);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
catch(const Py::Exception&)
|
||||
@@ -758,12 +778,19 @@ int @self.export.Name@::_setattr(char *attr, PyObject *value) // __setattr__ fun
|
||||
#ifndef DONT_CATCH_CXX_EXCEPTIONS
|
||||
catch(const Base::Exception& e) // catch the FreeCAD exceptions
|
||||
{
|
||||
std::string str;
|
||||
str += "FreeCAD exception thrown (";
|
||||
str += e.what();
|
||||
str += ")";
|
||||
PyObject *edict = PyDict_New();
|
||||
|
||||
PyDict_SetItemString(edict, "sclassname", PyString_FromString(typeid(e).name()));
|
||||
PyDict_SetItemString(edict, "sErrMsg", PyString_FromString(e.getMessage().c_str()));
|
||||
PyDict_SetItemString(edict, "sfile", PyString_FromString(e.getFile().c_str()));
|
||||
PyDict_SetItemString(edict, "iline", PyInt_FromLong(e.getLine()));
|
||||
PyDict_SetItemString(edict, "sfunction", PyString_FromString(e.getFunction().c_str()));
|
||||
PyDict_SetItemString(edict, "swhat", PyString_FromString(e.what()));
|
||||
|
||||
e.ReportException();
|
||||
PyErr_SetString(Base::BaseExceptionFreeCADError,str.c_str());
|
||||
PyErr_SetObject(Base::BaseExceptionFreeCADError, edict);
|
||||
Py_DECREF(edict);
|
||||
|
||||
return -1;
|
||||
}
|
||||
catch(const std::exception& e) // catch other c++ exceptions
|
||||
@@ -789,12 +816,18 @@ int @self.export.Name@::_setattr(char *attr, PyObject *value) // __setattr__ fun
|
||||
#else // DONT_CATCH_CXX_EXCEPTIONS
|
||||
catch(const Base::Exception& e) // catch the FreeCAD exceptions
|
||||
{
|
||||
std::string str;
|
||||
str += "FreeCAD exception thrown (";
|
||||
str += e.what();
|
||||
str += ")";
|
||||
PyObject *edict = PyDict_New();
|
||||
|
||||
PyDict_SetItemString(edict, "sclassname", PyString_FromString(typeid(e).name()));
|
||||
PyDict_SetItemString(edict, "sErrMsg", PyString_FromString(e.getMessage().c_str()));
|
||||
PyDict_SetItemString(edict, "sfile", PyString_FromString(e.getFile().c_str()));
|
||||
PyDict_SetItemString(edict, "iline", PyInt_FromLong(e.getLine()));
|
||||
PyDict_SetItemString(edict, "sfunction", PyString_FromString(e.getFunction().c_str()));
|
||||
PyDict_SetItemString(edict, "swhat", PyString_FromString(e.what()));
|
||||
|
||||
e.ReportException();
|
||||
PyErr_SetString(Base::BaseExceptionFreeCADError,str.c_str());
|
||||
PyErr_SetObject(Base::BaseExceptionFreeCADError, edict);
|
||||
Py_DECREF(edict);
|
||||
return -1;
|
||||
}
|
||||
catch(const Py::Exception&)
|
||||
|
||||
Reference in New Issue
Block a user