相关疑难解决方法(0)

Python"从使用中提升"

Python raiseraise 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)

python syntax exception-handling python-3.x

154
推荐指数
3
解决办法
4万
查看次数

标签 统计

exception-handling ×1

python ×1

python-3.x ×1

syntax ×1