Trying to catch integrity error with sqlaclhemey
- by Lostsoul
I'm having problems with trying to catch a error. I'm using pyramid/sqlalchemy and made a sign up form with email as the primary key. The problem is when a duplicate email is entered it raises a IntegrityError, so I'm trying to catch that error and provide a message but no matter what I do I can't catch it(the error keeps appearing).
try:
new_user = Users(email, firstname, lastname, password)
DBSession.add(new_user)
return HTTPFound(location = request.route_url('new'))
except IntegrityError:
message1 = "Yikes! Your email already exists in our system. Did you forget your password?"
I get the same message when I tried except exc.SQLAlchemyError (although I want to catch specific errors and not a blanket catch all).
Is there something wrong with my python syntax? or is there something I need to do special in sqlalchemy to catch it?