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

关于异常

  •  
  •   cevincheung ·
    cevin · Sep 21, 2017 · 2080 views
    This topic created in 3292 days ago, the information mentioned may be changed or developed.

    像这种有什么优雅的处理方法?

    try..except ? 但是错误异常太多了(像这个 exc.DataError,其他的还有 OptionError ),一个个 except ?

    dawncold
        1
    dawncold  
       Sep 21, 2017   ❤️ 1
    The base exception class is SQLAlchemyError. Exceptions which are raised as a result of DBAPI exceptions are all subclasses of DBAPIError.
    cevincheung
        2
    cevincheung  
    OP
       Sep 21, 2017
    @dawncold #1

    from sqlalchemy.exc import DBAPIError, SQLAlchemyError

    try:
    # code
    except DBAPIError:
    print('dbapi')
    except SQLAlchemyError:
    print('sqlalchemy')


    然而并没有什么事情发生
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2777 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 13:26 · PVG 21:26 · LAX 06:26 · JFK 09:26
    ♥ Do have faith in what you're doing.