[storm] Exception handling
akira
nhytro-python at web.de
Tue Sep 18 22:01:42 BST 2007
Hi all!
I am trying to handle exceptions returned from the DB API. For example,
I have a UNIQUE constraint on a field, when I try to save an object that
violates this I get this:
"duplicate key violates unique constraint"
So trying to handle the errors properly so that I can return the right
error to the user I have done some testing:
try:
store.add(user)
store.flush()
except Exception,e:
print e.__class__.__name__ # this emits an
"IntegrityError"
print Exception.__str__(e) # this print s"duplicate
key violates unique constraint "users_username_key'"
if Exception.__str__(e) == 'duplicate key violates unique
constraint "users_username_key':
print " this username has been taken....blablah" # This
does not work
if e.__class__.__name__ == 'IntegrityError":
print " this username has been taken....blablah" # This
works
Why does the first "if" conditional not work? Is this the right way to
handle such a problem? Should I try to handle all the exceptions that
might crop up? I am using postgresql, can I find all the defined
Exceptional that I would like to handle there?
Thanks in advance
More information about the storm
mailing list