有关于python里raise显示引发异常的方法:
- 当程序出错时,python会自动触发异常,也可以通过raise显示引发异常
- 一旦执行了raise语句,raise之后的语句不再执行
- 如果加入了try,except,那么except里的语句会被执行
try:
s = None
if s is None:
print(' s 为空')
raise NameError
print(len(s))
except Exception:
print('没有长度')