raise语句支持可选的from子句,该子句用于启用链式异常,例如:
raise RuntimeError from exc
异常链会在except或finally子句内部引发异常时自动生成,这可以通过使用from None这样的写法来禁用,实例如下:
try:
open('database.sqlite')
except OSError:
raise RuntimeError from None
Traceback (most recent call last):
File "<stdin>", line 4, in <module>
RuntimeError