summaryrefslogtreecommitdiffstats
path: root/Python/pythonrun.c
diff options
context:
space:
mode:
authorMartin Panter <vadmium+py@gmail.com>2016-02-28 03:16:11 (GMT)
committerMartin Panter <vadmium+py@gmail.com>2016-02-28 03:16:11 (GMT)
commit3263f6874a96c7b2862bd91460a28e66ac039dbe (patch)
tree7a730e6a8890fa5909b5500966cc838eac4862a5 /Python/pythonrun.c
parent738f88f688b7e490725bdcc9186a888998ca0370 (diff)
downloadcpython-3263f6874a96c7b2862bd91460a28e66ac039dbe.zip
cpython-3263f6874a96c7b2862bd91460a28e66ac039dbe.tar.gz
cpython-3263f6874a96c7b2862bd91460a28e66ac039dbe.tar.bz2
Issue #22836: Keep exception reports sensible despite errors
Diffstat (limited to 'Python/pythonrun.c')
-rw-r--r--Python/pythonrun.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index ebedd12..c03b073 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -766,8 +766,11 @@ print_exception(PyObject *f, PyObject *value)
/* only print colon if the str() of the
object is not the empty string
*/
- if (s == NULL)
+ if (s == NULL) {
+ PyErr_Clear();
err = -1;
+ PyFile_WriteString(": <exception str() failed>", f);
+ }
else if (!PyUnicode_Check(s) ||
PyUnicode_GetLength(s) != 0)
err = PyFile_WriteString(": ", f);
@@ -776,6 +779,9 @@ print_exception(PyObject *f, PyObject *value)
Py_XDECREF(s);
}
/* try to write a newline in any case */
+ if (err < 0) {
+ PyErr_Clear();
+ }
err += PyFile_WriteString("\n", f);
Py_XDECREF(tb);
Py_DECREF(value);