Created
July 12, 2010 05:33
-
-
Save tanakh/472150 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string GetPythonErrorString() | |
{ | |
try{ | |
PyObject *ptype, *pvalue, *ptraceback; | |
PyErr_Fetch(&ptype, &pvalue, &ptraceback); | |
object prev_stderr = import("sys").attr("stderr"); | |
object output_cacher = import("cStringIO").attr("StringIO")(); | |
import("sys").attr("stderr") = output_cacher; | |
PyErr_Restore(ptype, pvalue, ptraceback); | |
PyErr_Print(); | |
import("sys").attr("stderr") = prev_stderr; | |
return extract<string>(output_cacher.attr("getvalue")())(); | |
}catch(...){ | |
handle_exception(); | |
PyErr_Clear(); | |
return ""; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment