Philip Jenvey  committed ade5d5b

special case non BaseException values in excepthook

  • Participants
  • Parent commits 34a601c
  • Branches py3k

Comments (0)

Files changed (2)

File pypy/module/sys/

 def excepthook(exctype, value, traceback):
     """Handle an exception by displaying it with a traceback on sys.stderr."""
+    if not isinstance(value, BaseException):
+        sys.stderr.write("TypeError: print_exception(): Exception expected for "
+                         "value, {} found\n".format(type(value).__name__))
+        return
     # Flush stdout as well, both files may refer to the same file

File pypy/module/sys/test/

             raise ValueError(42)
         except ValueError as exc:
+        assert err.getvalue().endswith("ValueError: 42\n")
+        eh(1, '1', 1)
+        expected = ("TypeError: print_exception(): Exception expected for "
+                    "value, str found")
+        assert expected in err.getvalue()
         sys.stderr = savestderr
-        assert err.getvalue().endswith("ValueError: 42\n")
     def test_excepthook_failsafe_path(self):
         import traceback