I have a unique constraint defined at the database level which checks for a
combination of two fields name and postcode.
I need to report an error back to the user in the web-tier.
What is the best technique for this?
e.g the logic that inserts/updates the database will throw an SQLException if this constraint is violated, should i catch this exception and throw a valid user error.
or before making the update make a call to the database to check for this constraint violation ie run a query to see if there exists 1 or more rows with the name and postcode entry and then return an error message based on the resultset returned.
I dont like the first one as sqlexception can be thrown for other reasons than unique constraint violation
thanks in advance