推荐学习书目
› 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
sivacohan
V2EX  ›  Python

Python捕获异常的原理是什么?

  •  
  •   sivacohan ·
    SIvaCoHan · Mar 17, 2013 · 4125 views
    This topic created in 4939 days ago, the information mentioned may be changed or developed.
    用subprocess.Popen的时候,stderr = subprocess.PIPE 。
    这样就无法捕获异常了。

    python捕获异常依赖于stderr吗?如果是这样,我希望重定向stderr的输出,这个地方怎么处理呢?
    3 replies  •  1970-01-01 08:00:00 +08:00
    keakon
        1
    keakon  
       Mar 17, 2013 via iPad
    异常和 stderr 没关系啊。话说为什么不用 logging?
    aisk
        2
    aisk  
       Mar 17, 2013
    貌似Python的异常是所有函数调用都有个隐式返回结果,标明有没有异常发生,然后另外一个全局变量保存异常信息,except到异常的返回结果的话就去检查这个全局变量。

    楼主的问题依然不太明白啊。。。
    venglide
        3
    venglide  
       Mar 18, 2013
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2393 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 05:44 · PVG 13:44 · LAX 22:44 · JFK 01:44
    ♥ Do have faith in what you're doing.