[issue12029] Catching virtual subclasses in except clauses

James Henstridge report at bugs.python.org
Sat May 12 02:54:28 CEST 2012


James Henstridge <james at jamesh.id.au> added the comment:

Benjamin: if you are after a use case for this feature, see  https://code.djangoproject.com/ticket/15901

In Django, there are multiple database backends, each of which currently catch the adapter's DatabaseError and reraise it as Django's DatabaseError so that Django code can handle database errors in a standard way without having to care about which backend they came from.  Unfortunately, this loses some information from the exception.

My idea for solving that bug was to make Django's DatabaseError an ABC.  By registering the various adapter's DatabaseErrors with the ABC, it would not be necessary to catch and reraise them in the backends while still preserving the ability to catch the generic errors in the core.  This works fine in Python 2.x, but it was pointed out that it would cause compatibility problems when porting to Python 3.2.

----------
type: enhancement -> behavior

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12029>
_______________________________________


More information about the Python-bugs-list mailing list