异常处理

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)

 

posted @ 2019-02-13 23:38  ^sun^  阅读(113)  评论(0编辑  收藏  举报