推荐学习书目
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 · 2795 views
    This topic created in 3591 days ago, the information mentioned may be changed or developed.
    希望能够获得错误类型,然后将错误类型打印出来,然后让程序继续执行余下语句?

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

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

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


    这样呢
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2656 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 15:29 · PVG 23:29 · LAX 08:29 · JFK 11:29
    ♥ Do have faith in what you're doing.