I have a PHP script and some constraint rules in Mysql to prevent the user from deleting a category that contains products. But when the user try to delete the prohibited category he will face a fatal error instead of the website page
Fatal error: Uncaught PDOException: SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails...
I need to show an error like below instead of Fatal error:
You can not delete this category while it has products related.
Edit : note that the try/catch will not work for fatal errors