2 #include <boost/python.hpp> 11 #define HANDLE_PYTHON_EXCEPTION \ 12 std::string pythonErrorMessage = "none"; \ 13 if (PyErr_Occurred()) { \ 14 pythonErrorMessage = alsfvm::python::handle_pyerror(); \ 16 boost::python::handle_exception(); \ 18 THROW("Error running python script:\n" << pythonErrorMessage) 26 using namespace boost::python;
27 using namespace boost;
29 PyObject* exc, *val, *tb;
30 object formatted_list, formatted;
31 PyErr_Fetch(&exc, &val, &tb);
32 handle<> hexc(exc), hval(allow_null(val)), htb(allow_null(tb));
33 object traceback(
import(
"traceback"));
36 object format_exception_only(traceback.attr(
"format_exception_only"));
37 formatted_list = format_exception_only(hexc, hval);
39 object format_exception(traceback.attr(
"format_exception"));
40 formatted_list = format_exception(hexc, hval, htb);
43 formatted = str(
"\n").join(formatted_list);
44 return extract<std::string>(formatted);
std::string handle_pyerror()
Definition: handle_pyerror.hpp:25
Various utility functions to implement the tecno flux.
Definition: types.hpp:30