title: CodeIgniter: Try Catch is not working in model class
body: <p>I have a <code>unique</code> constraint on of the column. When this code runs, I get error log from framework but it is not what I have given in Exception block.<br/>
  If unique column exists then I want to query its primary key and set it as <code>$id</code> and return to the page. Right now it is stopping on db error and not going into <code>Catch block</code>.<br/>
  <strong>Here is my code:</strong></p>
  
  <pre><code>try {
              $result = $this-&gt;db-&gt;insert('email', $new_email);
              if ($result)
              {
                  $id = $this-&gt;db-&gt;insert_id();    
              } else {
                  throw new Exception("$$$$$$$$$$$$$Log database error");
              }
          } catch (Exception $e) {
              log_message('error',$e-&gt;getMessage());
              return;
          }
  </code></pre>
  
  <p><code>**Error Messages**</code> I get from framework:</p>
  
  <pre><code>DEBUG - 2013-04-07 05:00:38 --&gt; DB Transaction Failure
  ERROR - 2013-04-07 05:00:38 --&gt; Query error: Duplicate entry 
  </code></pre>
  
  <p>I don't know what is wrong with it.</p>