please use specific exception types in the documentation

Issue #1365 resolved
Former user created an issue

The tutorial at http://www.sqlalchemy.org/docs/05/ormtutorial.html#returning-lists-and-scalars has an example

>>> try:
...     user = query.one()
... except Exception, e:
...     print e

It is generally considered bad style to catch generic exceptions. I would therefore suggest that the example be amended to catch the specific exception that SQLAlchemy raises in one():

>>> from sqlalchemy.orm.exc import MultipleResultsFound
>>> try:
...     user = query.one()
... except MultipleResultsFound, e:
...     print e

and, in a similar way, the next example

>>> from sqlalchemy.orm.exc import NoResultFound
>>> try:
...     user = query.filter(User.id == 99).one()
... except NoResultFound, e:
...     print e

Comments (2)

  1. Log in to comment