V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2013-03-17 22:57:09 +08:00 · 3268 次点击
    这是一个创建于 4071 天前的主题,其中的信息可能已经有所发展或是发生改变。
    用subprocess.Popen的时候,stderr = subprocess.PIPE 。
    这样就无法捕获异常了。

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

    楼主的问题依然不太明白啊。。。
    venglide
        3
    venglide  
       2013-03-18 14:15:39 +08:00
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3203 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 14:16 · PVG 22:16 · LAX 07:16 · JFK 10:16
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.