Python2.7-内置异常类型

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python2.7-内置异常类型相关的知识,希望对你有一定的参考价值。

python内置了许多异常类型,他们的继承关系如下:
-----------------------------------------------
BaseException +-- SystemExit +-- KeyboardInterrupt +-- GeneratorExit +-- Exception +-- StopIteration +-- StandardError | +-- BufferError | +-- ArithmeticError | | +-- FloatingPointError | | +-- OverflowError | | +-- ZeroDivisionError | +-- AssertionError | +-- AttributeError | +-- EnvironmentError | | +-- IOError | | +-- OSError | | +-- WindowsError (Windows) | | +-- VMSError (VMS) | +-- EOFError | +-- ImportError | +-- LookupError | | +-- IndexError | | +-- KeyError | +-- MemoryError | +-- NameError | | +-- UnboundLocalError | +-- ReferenceError | +-- RuntimeError | | +-- NotImplementedError | +-- SyntaxError | | +-- IndentationError | | +-- TabError | +-- SystemError | +-- TypeError | +-- ValueError | +-- UnicodeError | +-- UnicodeDecodeError | +-- UnicodeEncodeError | +-- UnicodeTranslateError +-- Warning +-- DeprecationWarning +-- PendingDeprecationWarning +-- RuntimeWarning +-- SyntaxWarning +-- UserWarning +-- FutureWarning +-- ImportWarning +-- UnicodeWarning +-- BytesWarning
-------------------------------------------------
一般在自己编写程序的时候需要注意的就是
TypeError、ValueError
在编写继承关系的类时,定义基类的需要被子类覆盖的方法时要注意NotImplementedError
-------------------------------------------------
原文链接:https://docs.python.org/2/library/exceptions.html






以上是关于Python2.7-内置异常类型的主要内容,如果未能解决你的问题,请参考以下文章

python2.7入门---列表(List)

Python2.7-内置函数

解决Python2.7的UnicodeEncodeError: ‘ascii’ codec can’t encode异常错误

回味Python2.7——笔记3

解决Python2.7的UnicodeEncodeError: ‘ascii’ codec can’t encode异常错误

解决Python2.7的UnicodeEncodeError: ‘ascii’ codec can’t encode异常错误