成都网站建设设计

将想法与焦点和您一起共享

Python之程序异常处理

代码

#Author Kang

try:
    name = [1,2,3]
    print(name[2])   
    print(name[3])   #代码发生错误,执行Expection
except Exception as e:    #抓取所有错误
    print("错误信息:",e)

结果:
3
错误信息: list index out of range

网站栏目:Python之程序异常处理
网站地址:http://chengdu.cdxwcx.cn/article/gsjhoe.html