Python(十三)异常

异常及异常处理

try://执行第一步

    #int("hello world")

    int(123)

except (ValueError, TypeError) as reason://捕获异常

    print("出错啦:" + str(reason))

else://如果没有异常执行else

    print("执行正常")

finally://最终肯定要执行,除非程序提前退出

    print("finally exit...") 



 

    with语句***

猜你喜欢

转载自awenhaowenchao.iteye.com/blog/2409116