How do I ignore the errors thrown by the DB api?

Ben Finney bignose+hates-spam at
Wed Jun 14 04:30:04 CEST 2006

"fyleow" <fyleow at> writes:

> It would be great if I could just insert values into the DB and let
> the uniqueness check at the DB level to either add or refuse the
> duplicate value.

The Pythonic way to do this is find out what exception is generated by
the event you want to handle, and handle that exception.

    record_stuff = build_new_record()
    except FailedToInsert, e:
        handle_insert_failure(e, record_stuff)

Define each of those functions, name the actual exception class, and
you're done.

 \       "A lot of people are afraid of heights. Not me, I'm afraid of |
  `\                                        widths."  -- Steven Wright |
_o__)                                                                  |
Ben Finney

More information about the Python-list mailing list