[storm] Exception handling
James Henstridge
james at jamesh.id.au
Wed Sep 19 03:38:09 BST 2007
On 19/09/2007, Drew Smathers <drew.smathers at gmail.com> wrote:
> > if Exception.__str__(e) == 'duplicate key violates unique
> > constraint "users_username_key':
>
> This is a really bad idea, since the string message is by no means
> part of the contract of an exception - and in some systems may even be
> localized to some other language ;)
Furthermore, e will most likely be a subclass of Exception which might
override __str__(). Use str(e) instead if you want the
stringification of e.
As a more general point, it'd be better to check for the conflict
before adding the object. Once you get an error like this, you've
doomed your transaction and won't be able to perform any more database
operations until you rollback().
James.
More information about the storm
mailing list