3 ms·
Python handles this case by raising the new error but including a reference to the original error. By default, the formatted error shows both: >>> mylist =
by ekimekim 2y ago
Python handles this case by raising the new error but including a reference to the original error. By default, the formatted error shows both:
>>> mylist = []
>>> try:
... first = mylist[0]
... finally:
... inverse_length = 1.0 / len(mylist) # imagine this was something more complex
...
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>
ZeroDivisionError: float division by zero