Now, the result is:
>>>a = object.__new__(type(exit))
>>>b = {}
>>>b[a]
Traceback (most recent call last):
File "<python-input-2>", line 1, in <module>
b[a]
~^^^
KeyError: <exception str() failed>
As you see, we don’t know why the message show failed, we can just see the fuzzy message “<exception str() failed>”.
In fact, if the message need to use other object’s __repr__
and the __repr__
raise the Exception, the final message is it. It makes the debug difficult and maybe cause serious problem then.
To solve these problem, I have an ideal:
If the sys.excepthook
first try to use str(Exception) then raise, the new Exception will keep to use sys.excepthook
, but the count plus 1. If the count above 5, change to use sys.unraisablehook
to avoid the infinite loop. In this way we can show more detail while keep safe.