I'm developing a Drupal module. There is a table called currency. The currency_code column is set to be UNIQUE. When I try to enter a duplicate entry, drupal automatically shows an error message like this:-
.-------------------------------------------------------------------------. | user warning: Duplicate entry 'USD' for key 'currency_code' | | query: INSERT INTO currency(currency_id, currency_name, currency_code) | | VALUES (NULL, 'US Dollar', 'USD') in /xxx/currency/currency.admin.inc | | on line 106. | .-------------------------------------------------------------------------.
Obviously I cannot just let the user see this error. Instead I want to print a custom error message indicating the reason of the error (duplication of unique value in this case). So my question is how to I identify what is causing the error and display it in a user friendly manner (probably using drupal_set_message()).
Is there any way I can save the error message string in a variable, so that I can parse it in the background and print a cusom message?