Exception handling for Python function calls.

This commit is contained in:
Gunnar Beutner 2013-02-16 08:08:51 +01:00
parent 79bf945868
commit acf4e746c0
1 changed files with 16 additions and 2 deletions

View File

@ -94,8 +94,22 @@ void PythonInterpreter::ProcessCall(const ScriptTask::Ptr& task, const String& f
Py_DECREF(args);
if (result == NULL) {
// re-throw python exception
if (PyErr_Occurred()) {
PyObject *ptype, *pvalue, *ptraceback;
PyErr_Fetch(&ptype, &pvalue, &ptraceback);
PyObject *pstr_msg = PyObject_Str(pvalue);
PyObject *pstr_tb = PyObject_Str(ptraceback);
Py_DECREF(pvalue);
PyErr_Clear();
String msg = PyString_AsString(pstr_msg);
Py_DECREF(pstr_msg);
String tb = PyString_AsString(pstr_tb);
Py_DECREF(pstr_tb);
BOOST_THROW_EXCEPTION(runtime_error("Error in Python script:" + msg + " at " + tb));
}
Value vresult = PythonLanguage::MarshalFromPython(result);