Applications should branch on SQLSTATE, not on the error text. Class 23 covers integrity violations: 23505 unique, 23503 foreign key, 23514 check.
SQLSTATE
A five-character standard error code, e.g. 23505 for a unique violation.
Applications should branch on SQLSTATE, not on the error text. Class 23 covers integrity violations: 23505 unique, 23503 foreign key, 23514 check.