首页 > 其他 > 详细

异常处理

时间:2019-02-14 00:26:12      阅读:200      评论:0      收藏:0      [点我收藏+]
try:
    print("-------")
    open(123.txt, r)
except (IOError, NameError):
    print("######")
    pass


try:
    open(1.txt,r)
except:
    print("异常")


try:
    # open(‘1.txt‘, ‘r‘)
    print("1")
except Exception as result:
    print("异常")
    print(result)
else:
    print("没有异常")
finally:
    print("finally")


print("-----------------------")
try:
    try:
        print(1/0)
    except ValueError as e:
        print(e)
except ZeroDivisionError as e:
    print(e)


print("-----------------------")
try:
    try:
        1 / 0
    except ZeroDivisionError as e:
        print("无能为力,不能处理")
        raise
except ZeroDivisionError as e:
    print(e)

 

异常处理

原文:https://www.cnblogs.com/sunBinary/p/10372412.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!