Hide errors from users but show to admin?
Preface: This answer was first posted as an answer to "How do I suppress a warning or error message for site users?".

Disable Messages module

You could use the Disable Messages module for this. Here is a quote from its project page:


  Gives a site owner options to disable specific messages shown to end users. The core drupal message system as offered by drupal_set_message is an excellent way for modules to send out messages to the end users. However not all drupal site owners are keen to show all the messages sent out by drupal core and all modules to their users. This module gives site administrators a reasonably powerful way to filter out messages shown to the end users.


Some of its features are:


  
  Filter out messages that match a full text string exactly.
  Filter out messages that match a regular expression.
  Permissions to specifically hide all messages of a given type from any role.
  Disable all filtering for specific users.
  Disable all filtering for specific paths.
  Apply filtering only for specific paths.
  Debug system to get messages in the HTML without showing it to the end users.
  


Available for either Drupal 6, Drupal 7 or Drupal 8.

About using regular expressions

If you're using its 'regular expression' feature, you have to make sure that you use a regular expression that "catches" the error message you want to intercept, as explained also in the Community documentation.

Below "Tip: Keep it simple." on that page, there is a great sample, which looks like so:


  Be aware that something that appears very straightforward like:


Notice: Undefined index: field_txt_student_id in ctools_entity_form_field_content_type_render() (line 96 of [...]entity_form_field.inc).



  Has a lot more unseen characters in it than one might expect:


&lt;em class="placeholder"&gt;Notice&lt;/em&gt;: Undefined index: field_txt_student_id in &lt;em class="placeholder"&gt;ctools_entity_form_field_content_type_render()&lt;/em&gt; (line &lt;em class="placeholder"&gt;96&lt;/em&gt; of &lt;em class="placeholder"&gt;[...]entity_form_field.inc&lt;/em&gt;).



  So just wrap the meat of the grep with a simple "any character" regex: ".+" as in:


.+Notice.+Undefined index:.+ctools_entity_form_field_content_type_render.+entity_form_field.inc.+


So the "clue" to come up with a correct message, is to shrink the error message you want to catch, and putting ".+" characters where appropriate.

Talking about shrinking, note that the field_txt_student_id has been omitted in the regular expression also (to make it NOT depend on the field name).

Example

As another example, assume you want to catch this error message:


  PDOException: in dblog_watchdog() (line 160 of /home/dbuser/public_html/yoursitesname.com/modules/dblog/dblog.module).


In this case a possible regular expression should look something like so:

.+PDOException.+in dblog_watchdog().+(line 160 of.+/modules/dblog/dblog.module).+


Note how I intentionally did not include part of the path before /modules/dblog/dblog.module (so that it can be reused in another site where the very same error occurs ...).

Also note that you have to give it some thought to yes or no include the 160 part of it: if the module ever changes a bit so that in the error message it (eg) becomes line 161, your error will not be intercepted anymore. To avoid that, omit the 160 part of it, if that's what you prefer (personally I would rather first see the error coming back then, and then re-adapt my regular expression).

If your regular expression doesn't work at first (= the message still appears), then it might be because there is some typo in the regular expression. To pinpoint such typo, first try with a less restrictive regular expression, even if it was only to try with something like so (to catch ALL messages containing PDOException and dblog_watchdog):

.+PDOException.+dblog_watchdog.+


Or even like so (to catch ALL messages containing PDOException):

.+PDOException.+


These last 2 expressions would probably suppress way too much messages, so you'd want to narrow it down to that single one you're after.

Unstable alternative

There is also the Better Messages module as an alternative. However, for D7 (which is what this question is about), it only has an Alfa version.