对Python中内置异常层次结构详解
2018-10-18 09:16
1066 查看
如下所示:
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
想要捕获所有的异常,可以直接捕获 Exception 即可:
try: ... except Exception as e: ... log('Reason:', e) # Important!
这个将会捕获除了 SystemExit 、 KeyboardInterrupt 和 GeneratorExit 之外的所有异常。 如果你还想捕获这三个异常,将 Exception 改成 BaseException 即可。
以上这篇对Python中内置异常层次结构详解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。
您可能感兴趣的文章:
相关文章推荐
- Python中内置异常层次结构
- Python内置异常类层次关系
- java异常 之 异常的层次结构
- Python常用内置模块之xml模块(详解)
- Python pandas 数据框的str列内置的方法详解
- Python层次聚类sci.cluster.hierarchy.linkage函数详解
- python基础知识——内置数据结构(集合)
- 详解常用查找数据结构及算法(Python实现)
- Java 异常类层次结构
- python异常处理详解
- java异常层次结构
- 详解在Python中处理异常的教程
- 详解Python中内置的NotImplemented类型的用法
- python 的3大内置数据结构
- 【Java】Java异常类的层次结构
- Python标准异常和异常处理详解
- python异常 详解(续)
- Python——异常(内置异常以及应用场景)
- python的scipy层次聚类参数详解
- java基础- 异常的层次结构