title: zend framework 2 no catch PDO exceptions using Db Adapter
body: <p>I am using the Zend\Db\Adapter\Adapter to launch queries with PDO_Mysql driver. I want to catch the primary key violation with PDOException class.</p>
  
  <p>The following code catches correctly the exception and shows the first message. It's based on a query method with execute mode.</p>
  
  <pre><code>    try {
          $dbAdapter = new DbAdapter(array(
                  'driver' =&gt; 'Pdo_Mysql', 'database' =&gt; 'securedraw',
                  'username' =&gt; 'root', 'password' =&gt; '',));          
  
          $sql = "INSERT INTO users (mail, password) values('josep', 'josep')";
          $dbAdapter-&gt;query($sql, DbAdapter::QUERY_MODE_EXECUTE);
  
      }catch (\PDOException $e) {
          print "First Message " . $e-&gt;getMessage() . "&lt;br/&gt;";
      }catch (\Exception $e) {
          print "Second Message: " . $e-&gt;getMessage() . "&lt;br/&gt;";
      }
  </code></pre>
  
  <p>I don't understand because this code doesn't catch it (the unique change is that it's a prepared statement). </p>
  
  <p>In this case show the second message which is much more generic and doesn't said if the error is primary key violation.</p>
  
  <pre><code>    try {
          $dbAdapter = new DbAdapter(array(
                  'driver' =&gt; 'Pdo_Mysql', 'database' =&gt; 'securedraw',
                  'username' =&gt; 'root', 'password' =&gt; '',));          
  
          $sql = "INSERT INTO users (mail, password) values('josep', 'affsafq')";
          $statement = $dbAdapter-&gt;createStatement($sql);
          $statement-&gt;execute();  
  
      }catch (\PDOException $e) {
          print "First Message "   . $e-&gt;getMessage() . "&lt;br/&gt;";
      }catch (\Exception $e) {
          print "Second Message: " . $e-&gt;getMessage() . "&lt;br/&gt;";
      }
  </code></pre>