python第二天 - 异常处理

前端之家收集整理的这篇文章主要介绍了python第二天 - 异常处理前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

简单罗列一下知识点:

一、基本写法

try:
  html = _respose.read().decode('utf-8')
except Exception as e:
     pass

捕获多个异常

@H_404_12@try: x = int(input('input x:')) y = int(input(input y:)) print(x/y = ',x/y) except ZeroDivisionError: #捕捉除0异常 "ZeroDivision") except (TypeError,ValueError) as e: 捕捉多个异常,并将异常对象输出 print(e) except: 捕捉其余类型异常 it's still wrong")
else:#没有异常时运行
  print("no exeception")
finally:#不管有没有异常都要运行
  print("end")

注意是except而不是catch,写顺手容易写成catch

猜你在找的Python相关文章