码迷,mamicode.com
首页 > 编程语言 > 详细

python面向对象--异常处理

时间:2018-06-16 17:07:04      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:文件读写   ror   efi   python   val   数据   error   pytho   file   

1.常见异常类型

IOError 文件读写异常
ValueError值异常,一般是数据类型不对应
IndexError下标索引越界

2.try...except...

try:
    f=open(‘test.txt‘)
except IOError as e:
    print(e)
>>:
[Errno 2] No such file or directory: ‘test.txt‘     

3.错误基类Exception

try:
    print(a)
except Exception as e:
    print(e)
>>:     
name ‘a‘ is not defined     

python面向对象--异常处理

标签:文件读写   ror   efi   python   val   数据   error   pytho   file   

原文地址:http://blog.51cto.com/13803166/2130055

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!