python第二天 - 异常处理
简单罗列一下知识点:
一、基本写法
try:
html = _respose.read().decode('utf-8')
except Exception as e:
pass
捕获多个异常
try: x = int(input('input x:')) y = int(input('input y:')) print('x/y = ',x/y) except ZeroDivisionError: #捕捉除0异常 print("ZeroDivision") except (TypeError,ValueError) as e: #捕捉多个异常,并将异常对象输出 print(e) except: #捕捉其余类型异常 print("it's still wrong")
else:#没有异常时运行
print("no exeception")
finally:#不管有没有异常都要运行
print("end")
注意是except而不是catch,写顺手容易写成catch