PYTHON异常处理

# 异常处理
'''异常处理格式
try:
    程序
except Exception as 异常名称:
    异常处理部分
'''
try:
    for i in range(0,10):
        print(i)
        if (i==4):
            print(kkk)
    print("hello")
except Exception as err:
    print(err)

0
1
2
3
4
name 'kkk' is not defined

 

# 异常后的程序继续
for i in range(0,10):
    try:
        print(i)
        if (i==4):
            print(kkk)
    except Exception as err:
        print(err)
print("hello")

0
1
2
3
4
name 'kkk' is not defined
5
6
7
8
9
hello

posted @ 2019-07-23 16:17  Peach~  阅读(197)  评论(0编辑  收藏  举报