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

请问如何获取错误信息并让程序继续进行下去?

  •  
  •   Newyorkcity · Sep 25, 2016 · 2997 views
    This topic created in 3712 days ago, the information mentioned may be changed or developed.
    希望能够获得错误类型,然后将错误类型打印出来,然后让程序继续执行余下语句?

    谢谢
    7 replies  •  2016-09-26 14:28:46 +08:00
    Livid
    Livid
    MOD
    PRO
    Sep 25, 2016 via iPhone
    1
    try:
    except:

    及试试这个服务: https://sentry.io
    Newyorkcity
    Newyorkcity
    OP
    Sep 25, 2016
    2
    @Livid
    try
    except
    这个我知道,问题在于怎么得到错误信息并且将它赋值给一个变量,方便以后调用..
    谢谢
    terence4444
    terence4444
    Sep 25, 2016 via iPhone
    3
    except 下面可以 catch 到错误类型,看下文档去吧
    billlee
    billlee
    Sep 25, 2016
    5
    try:
      ...
    except Exception:
       type, value, traceback = sys.exc_info()
       print('{}: {}'.format(type.__name__, value))
    cortexm3
    cortexm3
    Sep 25, 2016
    6
    try:
    ... ...

    except Exception as e:
    ... ...
    linzhi
    linzhi
    Sep 26, 2016❤️1
    7
    try:
    ....
    except Exception as e:
    print traceback.format_exc()
    continue


    这样呢
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   3087 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 05:25 · PVG 13:25 · LAX 21:25 · JFK 00:25
    ♥ Do have faith in what you're doing.