catching constraint exceptions when inserting data