Raise DBAPI-style exceptions instead of SQLError where possible

Issue #706 resolved
Former user created an issue

Sorry if this is an old idea, but I couldn't find it in my searches...

Instead of converting DBAPI exceptions to generic SQLError, mirror each DBAPI DatabaseError subclass with an identically-named subclass of SQLError. Then the programmer can catch the exception he wants directly instead of having to catch all SQLErrors, check orig, and re-raise if it's not the right one.

Comments (3)

  1. Mike Bayer repo owner
    • changed milestone to 0.4.0
    • changed component to engine

    nice idea. The error classes would still be "wrapping" the original one, so we're just talking about the catches here. im not sure if the various DBAPIs are really consistent with when they throw OperationalError vs. IntegrityError etc.

    Id propose we change the hierarchy to be like this:

                 DBAPIError  <-- SQLError is a synonym for compat
                     ^
                     |
    InterfaceError / OperationalError / DataError / ...
    

    DBAPIError can use a metaclass or new to automatically produce the subclass corresponding to the given dbapi error.

    Also existing uses for DBAPIError which aren't wrapping a real dbapi error, theres like two or three, should go to ArgumentErrors or InvalidRequestErrors.

  2. Log in to comment