Python中的try-finally
2024-10-07 16:34:04
>>> try:
... raise KeyboardInterrupt
... finally:
... print('Goodbye, world!')
...
Goodbye, world!
KeyboardInterrupt
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
A finally clause is always executed before leaving the try statement, whether an exception has occurred or not. When an exception has occurred in the try clause and has not been handled by an except clause (or it has occurred in an except or else clause), it is re-raised after the finally clause has been executed. The finally clause is also executed “on the way out” when any other clause of the try statement is left via a break, continue or return statement.
最新文章
- Android raw to bmp
- canvas时钟
- Python的高级特性12:类的继承
- CSS3自动添加省略号
- 模拟系列(一)&mdash;&mdash;数字电路
- iOS UILabel根据字符串长度自动适应宽度和高度
- git .gitignore 文件 解决二进制文件冲突问题
- CF 295A Greg and Array (两次建树,区间更新,单点查询)
- [hackerrank]Even Odd Query
- BZOJ 1046 上升序列
- 使用Ueditor编辑器上传图片总结;
- 容器化系列 - GitLab启动和配置 on Docker
- 【Linux】Linux简介
- 怎么在多场景下使用不同的 git 账号 commit
- 几种方法来实现scp拷贝时无需输入密码
- LeetCode 51 N-Queens II
- js实现深拷贝的一些方法
- 《剑指offer》-栈的压入、弹出序列
- Mysql select id 加上order by 后结果不一致
- python多进程打印字符,加锁(Lock加锁)