Unique constraint and exception handling