From 3263f6874a96c7b2862bd91460a28e66ac039dbe Mon Sep 17 00:00:00 2001 From: Martin Panter Date: Sun, 28 Feb 2016 03:16:11 +0000 Subject: Issue #22836: Keep exception reports sensible despite errors --- Python/pythonrun.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'Python/pythonrun.c') diff --git a/Python/pythonrun.c b/Python/pythonrun.c index ebedd123f3..c03b07378a 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(": ", 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); -- cgit v1.2.1