Improvements to errors module docs

This commit is contained in:
Daniele Varrazzo 2019-02-11 01:09:20 +00:00
parent 3de4d17519
commit 7c148ecee4
2 changed files with 17 additions and 7 deletions

View File

@ -10,8 +10,9 @@
.. versionadded:: 2.8 .. versionadded:: 2.8
This module contains the classes psycopg raises upon receiving an error from This module exposes the classes psycopg raises upon receiving an error from
the database with a :sql:`SQLSTATE` value attached. The module is generated the database with a :sql:`SQLSTATE` value attached (available in the
`~psycopg2.Error.pgcode` attribute). The content of the module is generated
from the PostgreSQL source code and includes classes for every error defined from the PostgreSQL source code and includes classes for every error defined
by PostgreSQL in versions between 9.1 and 11. by PostgreSQL in versions between 9.1 and 11.
@ -53,8 +54,16 @@ idiomatic error handler:
except psycopg2.errors.LockNotAvailable: except psycopg2.errors.LockNotAvailable:
locked = True locked = True
For completeness, the module also exposes all the DB-API-defined classes and For completeness, the module also exposes all the :ref:`DB-API-defined
:ref:`a few psycopg-specific exceptions <extension-exceptions>` previously exceptions <dbapi-exceptions>` and :ref:`a few psycopg-specific ones
exposed by the `!extensions` module. One stop shop for all your mistakes... <extension-exceptions>` exposed by the `!extensions` module. One stop shop
for all your mistakes...
.. autofunction:: lookup .. autofunction:: lookup
.. code-block:: python
try:
cur.execute("LOCK TABLE mytable IN ACCESS EXCLUSIVE MODE NOWAIT")
except psycopg2.errors.lookup("55P03"):
locked = True

View File

@ -137,14 +137,15 @@ available through the following exceptions:
.. exception:: Warning .. exception:: Warning
Exception raised for important warnings like data truncations while Exception raised for important warnings like data truncations while
inserting, etc. It is a subclass of the Python `~exceptions.StandardError`. inserting, etc. It is a subclass of the Python `StandardError`
(`Exception` on Python 3).
.. exception:: Error .. exception:: Error
Exception that is the base class of all other error exceptions. You can Exception that is the base class of all other error exceptions. You can
use this to catch all errors with one single `!except` statement. Warnings use this to catch all errors with one single `!except` statement. Warnings
are not considered errors and thus not use this class as base. It are not considered errors and thus not use this class as base. It
is a subclass of the Python `!StandardError`. is a subclass of the Python `StandardError` (`Exception` on Python 3).
.. attribute:: pgerror .. attribute:: pgerror