对Python中内置异常层次结构详解


Posted in Python onOctober 18, 2018

如下所示:

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运行的17个时新手常见错误小结
Aug 07 Python
python检查序列seq是否含有aset中项的方法
Jun 30 Python
pycharm安装图文教程
May 02 Python
python中 chr unichr ord函数的实例详解
Aug 06 Python
Python实现的拟合二元一次函数功能示例【基于scipy模块】
May 15 Python
python爬取个性签名的方法
Jun 17 Python
Python读写zip压缩文件的方法
Aug 29 Python
python实现排序算法解析
Sep 08 Python
浅谈Python 递归算法指归
Aug 22 Python
django列表筛选功能的实现代码
Mar 27 Python
在django中实现choices字段获取对应字段值
Jul 12 Python
python 提高开发效率的5个小技巧
Oct 19 Python
Python运维开发之psutil库的使用详解
Oct 18 #Python
python实现自动登录后台管理系统
Oct 18 #Python
python 对给定可迭代集合统计出现频率,并排序的方法
Oct 18 #Python
python实现简单登陆系统
Oct 18 #Python
Python字典中的键映射多个值的方法(列表或者集合)
Oct 17 #Python
python字典值排序并取出前n个key值的方法
Oct 17 #Python
Python中创建二维数组
Oct 17 #Python
You might like
php adodb连接带密码access数据库实例,测试成功
2008/05/14 PHP
解析php时间戳与日期的转换
2013/06/06 PHP
php递归删除目录与文件的方法
2015/01/30 PHP
PHP文件操作实例总结【文件上传、下载、分页】
2018/12/08 PHP
php用xpath解析html的代码实例讲解
2019/02/14 PHP
PHP crypt()函数的用法讲解
2019/02/15 PHP
php使用curl模拟多线程实现批处理功能示例
2019/07/25 PHP
工作需要写的一个js拖拽组件
2011/07/28 Javascript
Jquery的hover方法让鼠标经过li时背景变色
2013/09/06 Javascript
javascript数组操作(创建、元素删除、数组的拷贝)
2014/04/07 Javascript
js锁屏解屏通过对$.ajax进行封装实现
2014/07/31 Javascript
浅析jQuery Mobile的初始化事件
2015/12/03 Javascript
jQuery Mobile 触摸事件实例
2016/06/04 Javascript
详解js树形控件—zTree使用总结
2016/12/28 Javascript
nodejs中向HTTP响应传送进程的输出
2017/03/19 NodeJs
Angular2使用Angular-CLI快速搭建工程(二)
2017/05/21 Javascript
详解Puppeteer 入门教程
2018/05/09 Javascript
详解基于Node.js的HTTP/2 Server实践
2018/05/31 Javascript
详解JavaScript中的坐标和距离
2019/05/27 Javascript
layui实现给某一列加点击事件
2019/10/26 Javascript
node.js中process进程的概念和child_process子进程模块的使用方法示例
2020/02/11 Javascript
[02:51]DOTA2英雄基础教程 风暴之灵
2013/12/23 DOTA
Python+matplotlib+numpy绘制精美的条形统计图
2018/01/02 Python
python如何查看微信消息撤回
2018/11/27 Python
pandas中DataFrame修改index、columns名的方法示例
2019/08/02 Python
韩国美国时尚服装和美容在线全球市场:KOODING
2018/11/07 全球购物
J2EE相关知识面试题
2013/08/26 面试题
中文系学生自荐信范文
2013/11/13 职场文书
自荐信封面
2013/12/04 职场文书
十佳班主任事迹材料
2014/01/18 职场文书
《争吵》教学反思
2014/02/15 职场文书
公司法定代表人授权委托书
2014/09/29 职场文书
运动会宣传稿100字
2015/07/23 职场文书
两行代码解决Jupyter Notebook中文不能显示的问题
2021/04/24 Python
Python 中random 库的详细使用
2021/06/03 Python
Python中生成随机数据安全性、多功能性、用途和速度方面进行比较
2022/04/14 Python