[Language]Python中错误与异常
2017-05-11 15:42
274 查看
简述
Python允许程序运行时检测错误,可以抛出异常并进行处理。代码中添加错误检测及异常处理,只要将代码放在try-except语句中,try之后的代码是要管理的代码,except之后的代码是错误发生时处理错误的代码。
try: filename = raw_input('Enter file name: ') fobj = open(filename, 'r') for eachLine in fobj: print(eachLine) fobj.close() except IOError: print("file open error")
相关文章推荐
- Python 2.7 Tutorial —— 错误和异常
- The Python Tutorial 3.2 - 8Errors and Exceptions(错误和异常)
- 解决Python2.7的UnicodeEncodeError: ‘ascii’ codec can’t encode异常错误
- Python 错误和异常小结
- Python 错误和异常小结
- 学学python(2):错误和异常
- python 错误和异常
- python错误和异常(1)
- 【python学习】之一、错误与异常
- Python学习 Part6:错误和异常
- Python指南--错误和异常
- 解决Python2.7的UnicodeEncodeError: ‘ascii’ codec can’t encode异常错误
- 【python学习】之一、错误与异常
- Python2.x的UnicodeEncodeError: ‘ascii’ codec can’t encode异常错误
- 请求错误[Python]网络爬虫(三):异常的处理和HTTP状态码的分类
- Python指南--错误和异常
- python学习(二)之文件处理与错误异常
- Python Tutorial(八):错误和异常
- Python 错误和异常小结
- [PYTHON] 核心编程笔记之十-Python错误和异常