https://blog.csdn.net/fengbingchun/article/details/119818521
raise [EXPRESSION [from EXPRESSION]]
raise Exception("var's value:{}".format(var))
def functionName( level ):
if level < 1:
raise Exception("Invalid level!", level)
# 触发异常后,后面的代码就不会再执行
functionName(0)
---------------------------------------------------------------------------
Exception Traceback (most recent call last)
Cell In[9], line 5
3 raise Exception("Invalid level!", level)
4 # 触发异常后,后面的代码就不会再执行
----> 5 functionName(0)
Cell In[9], line 3, in functionName(level)
1 def functionName( level ):
2 if level < 1:
----> 3 raise Exception("Invalid level!", level)
Exception: ('Invalid level!', 0)