Python raise和raise fromPython 之间的区别是什么?
try:
raise ValueError
except Exception as e:
raise IndexError
Run Code Online (Sandbox Code Playgroud)
产量
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
Run Code Online (Sandbox Code Playgroud)
和
try:
raise ValueError
except Exception as e:
raise IndexError from e
Run Code Online (Sandbox Code Playgroud)
产量
Traceback (most recent call last):
File "tmp.py", line 2, in <module>
raise ValueError …Run Code Online (Sandbox Code Playgroud)