what is the reasonable (best?) Exception handling strategy?

Petr Jakes petr at tpc.cz
Thu Jun 1 06:05:21 EDT 2006


I am a little bit confused by all possibilities for exceptions handling
in Python (probably because I am not skilled enough??) I did try to
search trough this list and reading Python tutorial about Errors and
Exceptions but didn't find some "general" answer about exception
handling policy (strategy).

In the following example each row can IMHO raise an exception (if the
Firebird service is not running for example, if the database is
corrupted etc.).

Do I have to write "try/except" clause on each row?

Or to write try/except block (function) where to handle (on one place)
all exceptions expected in the program code is a good idea?

Or do I have to write own "exception hook"?

What about unexpected exceptions? :(

def databasExample(h,d,u,p):
    import kinterbasdb; kinterbasdb.init(type_conv=200)
    con = kinterbasdb.connect(host=h, database=d,user=u, password=p)
    cur = con.cursor()
    insertStatement = cur.prep("some SQL statement......")
    cur.executemany(insertStatement, ListOfValues)
    con.commit()
    cur.close()

Generally I am trying to find some general advices or suggestions about
exception handling more than the specific answers to the above
mentioned code example.

Regards

Petr Jakes




More information about the Python-list mailing list