异常处理:显示异常信息,程序继续运行

此语句的作用是显示异常信息,便于调试和改进程序。

except Exception as err:

  print(err)

 

#异常处理
'''
异常处理格式
try:
程序
except Exception as 异常名称:
异常处理部分
'''
try:
  for i in range(0,10):
  print(i)
  if(i==4):
    print(jkj)
  print("hello")
except Exception as err:
  print(err)


#让异常后的程序继续
for i in range(0,10):
try:
  print(i)
  if(i==4):
    print(jkj)
except Exception as err:
  print(err)

posted @ 2020-02-13 13:17  cutefox  阅读(189)  评论(0)    收藏  举报