Print the error message returned from the SQL query I created a custom module where I am querying the database, for example with code similar to the following one.

$query = db_select('node', 'n');
$query-&gt;fields('n', array('nid'));
$nid = $query-&gt;execute()-&gt;fetchField();


I want to print the warning, error, and success messages after the execution of the query. How can I achieve this?
Try to follow below code..

   try {
        $query = db_select('node', 'n');
        $query-&gt;fields('n', array('nid'));
        $nid = $query-&gt;execute()-&gt;fetchField();
        drupal_set_message(t('Print your sucess message here'));
      }
    catch(Exception $e){
        drupal_set_message(t('Print your error message here'),'error');
    }