Issue #22836: Keep exception reports sensible despite errors
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index ece709c..9b5f62d 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -1299,8 +1299,11 @@
             /* 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 (!PyString_Check(s) ||
                      PyString_GET_SIZE(s) != 0)
                 err = PyFile_WriteString(": ", f);
@@ -1309,6 +1312,9 @@
             Py_XDECREF(s);
         }
         /* try to write a newline in any case */
+        if (err < 0) {
+            PyErr_Clear();
+        }
         err += PyFile_WriteString("\n", f);
     }
     Py_DECREF(value);