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
Newyorkcity
V2EX  ›  Python

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

  •  
  •   Newyorkcity · 2016-09-25 11:35:38 +08:00 · 2217 次点击
    这是一个创建于 2778 天前的主题,其中的信息可能已经有所发展或是发生改变。
    希望能够获得错误类型,然后将错误类型打印出来,然后让程序继续执行余下语句?

    谢谢
    7 条回复    2016-09-26 14:28:46 +08:00
    Livid
        1
    Livid  
    MOD
       2016-09-25 11:38:11 +08:00 via iPhone
    try:
    except:

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

    except Exception as e:
    ... ...
    linzhi
        7
    linzhi  
       2016-09-26 14:28:46 +08:00   ❤️ 1
    try:
    ....
    except Exception as e:
    print traceback.format_exc()
    continue


    这样呢
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2253 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 03:36 · PVG 11:36 · LAX 20:36 · JFK 23:36
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.