# Python异常处理

# Python异常处理
Python程序在执行的时候,经常会遇到异常,如果中间异常不处理,经常会导致程序崩溃。
比如后面我们写爬虫的时候,如果不进行异常处理,很可能虫爬了一半,直接崩溃了。
异常处理的目的就是为了解决异常,使程序继续下去。为了让程序具有顽强的生命力,遇到异常也可以执行下去。
#异常处理格式
'''
try:
  程序
except Exception as 异常名称
  异常处理部分
'''
try:
    for i in range(0,10):
        print(i)
        if (i==4):
            print(kds)
    print('end')
except Exception as err:
    print(err)
    print('Program error and stop.')

#程序可以继续执行下去
for i in range(0,10):
    try:
        print(i)
        if (i==4):
            print(kds)
    except Exception as err:
        print(err)
print('end')


end