Index: Python/pythonrun.c =================================================================== --- Python/pythonrun.c (revision 66009) +++ Python/pythonrun.c (working copy) @@ -1301,9 +1301,10 @@ PyObject *type, *tb; if (!PyExceptionInstance_Check(value)) { - PyFile_WriteString("TypeError: print_exception(): Exception expected for value, ", f); - PyFile_WriteString(Py_TYPE(value)->tp_name, f); - PyFile_WriteString(" found\n", f); + PyErr_Format(PyExc_TypeError, + "Exception instance expected, not %.200s", + Py_TYPE(f)->tp_name); + PyErr_WriteUnraisable(PyUnicode_FromString("print_exception")); return; } Index: Lib/test/test_sys.py =================================================================== --- Lib/test/test_sys.py (revision 66009) +++ Lib/test/test_sys.py (working copy) @@ -65,8 +65,7 @@ def test_excepthook(self): with test.support.captured_output("stderr") as stderr: sys.excepthook(1, '1', 1) - self.assert_("TypeError: print_exception(): Exception expected for " \ - "value, str found" in stderr.getvalue()) + self.assert_("Exception instance expected, not" in stderr.getvalue()) # FIXME: testing the code for a lost or replaced excepthook in # Python/pythonrun.c::PyErr_PrintEx() is tricky.