V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
expkzb
V2EX  ›  Python

关于异常处理的问题

  •  
  •   expkzb · Aug 28, 2019 · 1971 views
    This topic created in 2444 days ago, the information mentioned may be changed or developed.
    平时拿 python 写点小脚本没什么问题,也挺方便的。一旦代码量大了,时不时就会有一些意想不到的异常被抛出。
    怎样优雅的获取所有可能的异常类型,从而可以针对它们进行处理呢?
    2 replies    2019-08-30 11:31:14 +08:00
    TimePPT
        1
    TimePPT  
    PRO
       Aug 28, 2019 via iPhone
    看异常的原因是啥。
    整体上,善用 debug 调试工具和 log 模块,分块对代码进行处理与现场记录,减少因 Bug 导致的抛异常
    另一方面,对外部请求的调用异常(比如 http 请求的各类异常),适当使用 try,对常见异常进行捕捉判断处理,增加代码容错性。
    Dustyposa
        2
    Dustyposa  
       Aug 30, 2019
    Python 异常消耗小,可以多用异常进行测试
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3052 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 15:06 · PVG 23:06 · LAX 08:06 · JFK 11:06
    ♥ Do have faith in what you're doing.