如何用新类型重新引发 Python 异常?
在 Python 3.x 中,代码受异常链的影响,我们获得的输出如下所示
C:/Users/TutorialsPoint1/~.py Traceback (most recent call last): File "C:/Users/TutorialsPoint1/~.py", line 2, in <module> 1/0 ZeroDivisionError: division by zero
上述异常是导致以下异常的直接原因
Traceback (most recent call last): File "C:/Users/TutorialsPoint1/~.py", line 4, in <module> raise ValueError ( "Sweet n Sour grapes" ) from e ValueError: Sweet n Sour grapes
广告