Skip to content

Commit 16b35ac

Browse files
committed
Merge remote-tracking branch 'origin/errors-module-c'
2 parents f1e7350 + 7c148ec commit 16b35ac

File tree

12 files changed

+603
-1538
lines changed

12 files changed

+603
-1538
lines changed

doc/src/errors.rst

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010

1111
.. versionadded:: 2.8
1212

13-
This module contains the classes psycopg raises upon receiving an error from
14-
the database with a :sql:`SQLSTATE` value attached. The module is generated
13+
This module exposes the classes psycopg raises upon receiving an error from
14+
the database with a :sql:`SQLSTATE` value attached (available in the
15+
`~psycopg2.Error.pgcode` attribute). The content of the module is generated
1516
from the PostgreSQL source code and includes classes for every error defined
1617
by PostgreSQL in versions between 9.1 and 11.
1718

@@ -53,8 +54,16 @@ idiomatic error handler:
5354
except psycopg2.errors.LockNotAvailable:
5455
locked = True
5556
56-
For completeness, the module also exposes all the DB-API-defined classes and
57-
:ref:`a few psycopg-specific exceptions <extension-exceptions>` previously
58-
exposed by the `!extensions` module. One stop shop for all your mistakes...
57+
For completeness, the module also exposes all the :ref:`DB-API-defined
58+
exceptions <dbapi-exceptions>` and :ref:`a few psycopg-specific ones
59+
<extension-exceptions>` exposed by the `!extensions` module. One stop shop
60+
for all your mistakes...
5961

6062
.. autofunction:: lookup
63+
64+
.. code-block:: python
65+
66+
try:
67+
cur.execute("LOCK TABLE mytable IN ACCESS EXCLUSIVE MODE NOWAIT")
68+
except psycopg2.errors.lookup("55P03"):
69+
locked = True

doc/src/module.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,15 @@ available through the following exceptions:
137137
.. exception:: Warning
138138

139139
Exception raised for important warnings like data truncations while
140-
inserting, etc. It is a subclass of the Python `~exceptions.StandardError`.
140+
inserting, etc. It is a subclass of the Python `StandardError`
141+
(`Exception` on Python 3).
141142

142143
.. exception:: Error
143144

144145
Exception that is the base class of all other error exceptions. You can
145146
use this to catch all errors with one single `!except` statement. Warnings
146147
are not considered errors and thus not use this class as base. It
147-
is a subclass of the Python `!StandardError`.
148+
is a subclass of the Python `StandardError` (`Exception` on Python 3).
148149

149150
.. attribute:: pgerror
150151

0 commit comments

Comments
 (0)