[Python] Handle Exceptions to prevent crashes in Python
2024-09-08 00:36:43
Exceptions cause your application to crash. Handling them allows you to recover gracefully and keep your application running. Learn how to handle exceptions, find what exceptions you should be handling, and exit gracefully in this lesson. You will also learn how you should not handle exceptions and when it is better to let your application crash rather than swallowing an exception.
import sys # print(int(sys.argv[1]) / int(sys.argv[2])) try:
print(int(sys.argv[1]) / int(sys.argv[2]))
except ValueError as e:
print('You must enter a valid number')
except ZeroDivisionError as e:
print("You can't divide by zero")
Built in: https://docs.python.org/3/library/exceptions.html#bltin-exceptions
Requests: http://docs.python-requests.org/en/master/_modules/requests/exceptions/
最新文章
- curl方法post一个数组
- java学习之协调同步的线程
- java邮件
- IOS 免受xib自动布局影响
- java web 学习十一(使用cookie进行会话管理)
- VOA学习-South Sudan Must Allow Aid
- 【HDOJ】1080 Human Gene Functions
- iOS模拟器分辨率的问题(转载)
- Android用surface直接显示yuv数据(二)
- 组队赛第二场:字符串哈希+DP
- SVN-钩子祥解与配置
- 中国大学MOOC-陈越、何钦铭-数据结构-2015秋 01-复杂度2 Maximum Subsequence Sum (25分)
- react native navigationOptions中不能获取this
- Navicat for Mysql导入mysql数据库脚本文件
- Problem A: STL——灵活的线性表
- Linux命令:popd
- contains用法
- 2018.09.29 Lua
- P1316 丢瓶盖(二分+贪心)
- react 使用 react-loadable分包