python如何检测和处理异常_Python中的异常处理

Python 2.4.4 (#2, Apr 5 2007, 20:11:18)

[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>> import exceptions

>>> print exceptions.__doc__

Python's standard exception class hierarchy.

Before Python 1.5, the standard exceptions were all simple string objects.

In Python 1.5, the standard exceptions were converted to classes organized

into a relatively flat hierarchy. String-based standard exceptions were

optional, or used as a fallback if some problem occurred while importing

the exception module. With Python 1.6, optional string-based standard

exceptions were removed (along with the -X command line flag).

The class exceptions were implemented in such a way as to be almost

completely backward compatible. Some tricky uses of IOError could

potentially have broken, but by Python 1.6, all of these should have

been fixed. As of Python 1.6, the class-based standard exceptions are

now implemented in C, and are guaranteed to exist in the Python

interpreter.

Here is a rundown of the class hierarchy. The classes found here are

inserted into both the exceptions module and the `built-in' module. It is

recommended that user defined class based exceptions be derived from the

`Exception' class, although this is currently not enforced.

Exception

|

+-- SystemExit

+-- StopIteration

+-- StandardError

| |

| +-- KeyboardInterrupt

| +-- ImportError

| +-- EnvironmentError

| | |

| | +-- IOError

| | +-- OSError

| | |

| | +-- WindowsError

| | +-- VMSError

| |

| +-- EOFError

| +-- RuntimeError

| | |

| | +-- NotImplementedError

| |

| +-- NameError

| | |

| | +-- UnboundLocalError

| |

| +-- AttributeError

| +-- SyntaxError

| | |

| | +-- IndentationError

| | |

| | +-- TabError

| |

| +-- TypeError

| +-- AssertionError

| +-- LookupError

| | |

| | +-- IndexError

| | +-- KeyError

| |

| +-- ArithmeticError

| | |

| | +-- OverflowError

| | +-- ZeroDivisionError

| | +-- FloatingPointError

| |

| +-- ValueError

| | |

| | +-- UnicodeError

| | |

| | +-- UnicodeEncodeError

| | +-- UnicodeDecodeError

| | +-- UnicodeTranslateError

| |

| +-- ReferenceError

| +-- SystemError

| +-- MemoryError

|

+---Warning

|

+-- UserWarning

+-- DeprecationWarning

+-- PendingDeprecationWarning

+-- SyntaxWarning

+-- OverflowWarning

+-- RuntimeWarning

+-- FutureWarning

>>>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值