Drupal 7 db_insert() execute() error when table contains unique keys
PHP has exception handling in the form of try...catch blocks:

try {
  $insert = db_insert('mymodule_mytable')-&gt;fields($fieldarray)-&gt;execute();
}
catch (PDOException $e) {
  drupal_set_message(t('Error: %message', array('%message' =&gt; $e-&gt;getMessage())), 'error');
}


So rather than ignore the error completely, you can actually respond to different types of exception and react accordingly.