Python nested exceptions

Hi, I have noticed a strange behavior with Python. Exceptions occurring when handling a previous exception show a truncated error message. In CPython, the code

try:
  [][0]  # IndexError
except IndexError:
  {}[0]  # KeyError

outputs the following error

Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
IndexError: list index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 4, in <module>
KeyError: 0

In CodinGame, only the initial exception is shown, making it look like it was not caught. It would be better to keep the last three lines rather than the first three. Thank you for looking at this!

More about…System level Exceptions Vs Application level Exceptions

Antonio