python异常
Std 异常
| 异常名 | 描述 | |
|---|---|---|
| 1 | Exception | 所有的异常 |
| 2 | StopIteration | 迭代器的next()方法不指向任何对象 |
| 3 | SystemExit | sys.exit() 函数执行 |
| 4 | StandardError | 除了StopIteration 和SystemExit之外的所有异常 |
| 5 | ArithmeticError | 所有数值计算的错误 |
| 6 | OverflowError | 数据类型溢出 |
| 7 | FloatingPointError | 浮点计算错误 |
| 8 | ZeroDivisonError | 对0取余或除以0 |
| 9 | AssertionError | 断言失败 |
| 10 | AttributeError | 属性的引用或赋值错误 |
| 11 | EOFError | 到达文件尾但没有从raw_imput()或input()读入任何数据 |
| 12 | ImportError | import导入失败 |
| 13 | KeyboardInterrupt | 用户通过键盘中断程序执行,通常时按了Ctrl+C |
| 14 | LookupError | 所有的搜索错误 |
| 15 | IndexError | 在序列中找不到索引 |
| 16 | KeyError | 在字典中找不到指定的键 |
| 17 | NameError | 找不到标识符 |
| 18 | UnboundLocalError | 访问的局部变量没有值 |
| 19 | EnvironmentError | 所有在Python的环境外引发的异常 |
| 20 | IOError | 输入输出操作无效 |
| 21 | OSError | 操作系统相关异常 |
| 22 | SyntaxError | Python语法错误 |
| 23 | IndentationError | 缩进格式错误 |
| 24 | SystemError | Python解释器内部错误,但错误发生时解释器还没有退出 |
| 25 | SystemExit | 调用了sys.exit() ,如果这个异常没有被handled,解释器会退出 |
| 26 | ValueError | 变量的值与数据类型不匹配 |
| 27 | RuntimeError | 发生了一个不属于任何已知异常类型的异常 |
| 28 | NotImplementedError | 应在在子类中执行的虚方法没有被执行 |
try...exception...else...
try:
You do your operations here;
...
except(Exception1[, Exception2[,...ExceptionN]]]):
If there is any exception from the given exception list,
then execute this block.
...
else:
If there is no exception then execute this block.
try...finally...
try:
You do your operations here;
...
Due to any exception, this may be skipped.
finally:
This would always be executed.
...
raise [Exception [, args [, traceback]]]
引发一个错误
def functionName( level ):
if level < 1:
raise "Invalid level!", level
# The code below to this would not be executed
# if we raise the exception
自定义异常
class Networkerror(RuntimeError):
def __init__(self, arg):
self.args = arg
引发自定义异常:
try:
raise Networkerror("Bad hostname")
except Networkerror,e:
print e.args
python异常的更多相关文章
- python 异常
引用一段来自菜鸟教程的文章:http://www.runoob.com/python/python-exceptions.html Python 异常处理 python提供了两个非常重要的功能来处理p ...
- #21 Python异常
前言 运行程序时经常遇到各种错误,例如:ImportError(导入模块错误).IndexError(索引错误).NameError(变量错误).SyntaxError(语法错误).Indentati ...
- Python异常和异常处理
Python异常和异常处理2017年12月20日 22:17:08 Megustas_JJC 阅读数:114 标签: python 异常处理 更多 个人分类: Python 版权声明:本文为博主原创文 ...
- python——异常except语句用法与引发异常
except: #捕获所有异常 except: <异常名>: #捕获指定异常 except:<异常名1,异常名2):捕获异常1或者异常2 except:<异常名>,< ...
- 笔记-python异常信息输出
笔记-python异常信息输出 1. 异常信息输出 python异常捕获使用try-except-else-finally语句: 在except 语句中可以使用except as e,然后通 ...
- python异常捕获异常堆栈输出
python异常捕获异常堆栈输出 学习了:https://blog.csdn.net/chris_grass/article/details/77927902 import traceback def ...
- 小学生绞尽脑汁也学不会的python(异常,约束,MD5加密,日志处理)
小学生绞尽脑汁也学不会的python(异常,约束,MD5加密,日志处理) 异常处理(处理) 1.产生异常.raise 异常类(),抛出异常2. 处理异常: try: xxxxx # 尝试执行的代码. ...
- python 异常之进阶操作
1.文件分析 下面来做一些文件分析操作,分析整本书的信息. 知识点: string.split():将字符串分解为列表. open(filename,‘rb’)或者open(filename,enco ...
- Python异常类型及包含关系
Python异常类型及包含关系,设计异常捕获时参考: BaseException +-- SystemExit +-- KeyboardInterrupt +-- GeneratorExit +-- ...
- 如何处理python异常
1.python异常有那些? window的机器如果安装了python,则直接可以在idle中查看,打开idle,按F1即可打开帮助文档,按如下路径即可查看,也可以去python官网查看这里不说明了百 ...
随机推荐
- FPGA中的delay与latency
delay和latency都有延迟的意义,在FPGA中二者又有具体的区别. latency出现在时序逻辑电路中,表示数据从输入到输出有效经过的时间,通常以时钟周期为单位. delay出现在组合逻辑电路 ...
- Servlet过滤器Filter用法
1 Servlet 过滤器方法 过滤器是一个实现了 javax.servlet.Filter 接口的 Java 类.javax.servlet.Filter 接口定义了三个方法:public void ...
- svg-高斯模糊+swiper伦播
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- windows的IIS下的负载均衡
来自http://www.cnblogs.com/allen0118/p/4294066.html 在大型Web应用系统中,由于请求的数据量过大以及并发的因素,导致Web系统会出现宕机的现象,解决这一 ...
- 用Microsoft.Solver.Foundation进行线性规划,为WPF应用添加智能
在管理信息系统的开发过程中,往往会涉及到一些线性规划数学模型,例如资源配置优化.微软的Microsoft.Solver.Foundation是一个数学库,可以很好的对线性规划问题进行求解.关于它的细节 ...
- jquery实现输入框实时输入触发事件代码
$('.aa').bind('input propertychange', function() { searchProductClassbyName(); }); function searchPr ...
- ASP.NET程序中常用的三十三种代码
1. 打开新的窗口并传送参数: 传送参数: response.write("<script>window.open(’*.aspx?id="+this.DropDown ...
- CSS3利用text-shadow属性实现多种效果的文字样式展现
一.效过图展示: 已经是比较久之前学习的文字效果了.但是还是很实用很有趣的.利用CSS3提供的text-shadow属性可以给页面上的文字添加阴影效果,因此可以替换掉之前使用过的一些繁琐的图片.到目前 ...
- An interesting experiment on China’s censorship
This paper presented a very interesting topic. Censorship in China has always drawn people's attenti ...
- 【即时通讯】XMPP调试与简单使用
上篇讲了[即时通讯]即时通讯及XMPP概述及环境配置,接下来我们就要进行调试,看看是否可用! 在测试之前我们需要先事先保存一些东西,以便后面使用 —— 登录openfire后台 ——获取服务器名和端口 ...