title: PDO PHP Uncaught exception
body: <p>I have currently switched to using PDO but am having trouble in handling the exceptions. The connection is correct and queries work perfectly, but when I put in a deliberate mistake the error is not handled as I would expect.</p>
  
  <p>I have changed the name of the table in my query to a table that does not exist. From the code seen below, I would expect the page to print out 'Database Error' but instead get the horrible orange error saying... </p>
  
  <p>'Uncaught exception 'PDOException' with message 'SQLSTATE[42S02]: Base table or view not found: 1146 Table 'test.post' doesn't exist' in C:\wamp\www\website\functions.php on line 46'</p>
  
  <p>Here is the code when connecting the database...</p>
  
  <pre><code>$hostname = 'localhost';
  $username = '';
  $password = '';
  try{
      $dbh = new PDO("mysql:host=$hostname;dbname=test", $username, $password);
      $dbh-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  } catch (PDOException $e) {
       print ("Database Error");
  }
  </code></pre>
  
  <p>Am I making a mistake or is there a different way to handle PDO errors? </p>