最佳答案
在Python中raise
和raise from
有什么区别?
try:
raise ValueError
except Exception as e:
raise IndexError
的收益率
Traceback (most recent call last):
File "tmp.py", line 2, in <module>
raise ValueError
ValueError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "tmp.py", line 4, in <module>
raise IndexError
IndexError
而且
try:
raise ValueError
except Exception as e:
raise IndexError from e
的收益率
Traceback (most recent call last):
File "tmp.py", line 2, in <module>
raise ValueError
ValueError
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "tmp.py", line 4, in <module>
raise IndexError from e
IndexError