try … except … as error in Python 2.5 – Python 3.x [duplicate]

You can use one code base on Pythons 2.5 through 3.2, but it isn’t easy. You can take a look at coverage.py, which runs on 2.3 through 3.3 with a single code base.

The way to catch an exception and get a reference to the exception that works in all of them is this:

except ValueError:
    _, err, _ = sys.exc_info()
    #.. use err...

This is equivalent to:

except ValueError as err:
    #.. use err...

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)