handle C++ exception in Python interface
This commit is contained in:
@@ -69,8 +69,15 @@ int CommandPy::PyInit(PyObject* args, PyObject* kwd)
|
||||
if ( PyArg_ParseTupleAndKeywords(args, kwd, "|sO!", kwlist, &name, &PyDict_Type, ¶meters) ) {
|
||||
std::string sname(name);
|
||||
boost::to_upper(sname);
|
||||
if (!sname.empty())
|
||||
getCommandPtr()->setFromGCode(name);
|
||||
try {
|
||||
if (!sname.empty())
|
||||
getCommandPtr()->setFromGCode(name);
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
PyErr_SetString(PyExc_ValueError, e.what());
|
||||
return -1;
|
||||
}
|
||||
|
||||
PyObject *key, *value;
|
||||
Py_ssize_t pos = 0;
|
||||
while (parameters && PyDict_Next(parameters, &pos, &key, &value)) {
|
||||
@@ -114,8 +121,14 @@ int CommandPy::PyInit(PyObject* args, PyObject* kwd)
|
||||
if ( PyArg_ParseTupleAndKeywords(args, kwd, "|sO!", kwlist, &name, &(Base::PlacementPy::Type), ¶meters) ) {
|
||||
std::string sname(name);
|
||||
boost::to_upper(sname);
|
||||
if (!sname.empty())
|
||||
getCommandPtr()->setFromGCode(name);
|
||||
try {
|
||||
if (!sname.empty())
|
||||
getCommandPtr()->setFromGCode(name);
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
PyErr_SetString(PyExc_ValueError, e.what());
|
||||
return -1;
|
||||
}
|
||||
Base::PlacementPy *p = static_cast<Base::PlacementPy*>(parameters);
|
||||
getCommandPtr()->setFromPlacement( *p->getPlacementPtr() );
|
||||
return 0;
|
||||
@@ -210,7 +223,14 @@ PyObject* CommandPy::setFromGCode(PyObject *args)
|
||||
char *pstr=0;
|
||||
if (PyArg_ParseTuple(args, "s", &pstr)) {
|
||||
std::string gcode(pstr);
|
||||
getCommandPtr()->setFromGCode(gcode);
|
||||
try {
|
||||
getCommandPtr()->setFromGCode(gcode);
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
PyErr_SetString(PyExc_ValueError, e.what());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user