22#include <boost/python/extract.hpp>
23#include <boost/python/handle.hpp>
24#include <boost/python/object.hpp>
33 PyObject *ptype, *pvalue, *ptraceback;
34 PyErr_Fetch(&ptype, &pvalue, &ptraceback);
35 PyErr_NormalizeException(&ptype, &pvalue, &ptraceback);
42 py::object err_msg_obj(py::handle<>(PyObject_Str(pvalue)));
43 m_error_msg = py::extract<std::string>(err_msg_obj);
45 py::object err_repr_obj(py::handle<>(PyObject_Repr(pvalue)));
46 m_error_msg = py::extract<std::string>(err_repr_obj);
48 py::object err_msg_type(py::handle<>(PyObject_GetAttrString(ptype,
"__name__")));
53 for (
auto traceback =
m_error_traceback; traceback; traceback = traceback.attr(
"tb_next")) {
55 loc.
lineno = py::extract<long>(traceback.attr(
"tb_lineno"));
56 loc.
filename = py::extract<std::string>(traceback.attr(
"tb_frame").attr(
"f_code").attr(
"co_filename"));
57 loc.
funcname = py::extract<std::string>(traceback.attr(
"tb_frame").attr(
"f_code").attr(
"co_name"));
73 msg <<
"File \"" << trace.filename <<
"\", line " << trace.lineno <<
", in " << trace.funcname;
static Elements::Logging logger
Logger.
void log(log4cpp::Priority::Value level, const std::string &logMessage)
boost::python::object m_error_traceback
void restore() const
Call PyErr_Restore and restore the error. This can be used when Pyston::Exception goes back to Python...
std::list< Location > m_traceback
const std::list< Location > & getTraceback() const
boost::python::object m_error_type
boost::python::object m_error_value
const Exception & log(log4cpp::Priority::Value level, Elements::Logging &logger) const
Log error message and traceback.