title: How to use try-catch block in PHP CodeIgniter
body: <p>I am working in PHP CodeIgniter and when I am trying to apply a try and catch block in my code then it is not working and does not handle the error. I have tried the try-catch block in both place Model and Controller but it is not working. My code is shown below.</p>
  
  <pre><code>try {
              $data = array(
                  'userid' =&gt; '101',
                  'pass' =&gt; '123456',
                  'usertyp' =&gt; 2,
                  'createddate' =&gt; "now()");
               $this-&gt;db-&gt;insert('login', $data);
       }
       catch (Exception $ex) 
       {
              echo $ex;
       }
  </code></pre>
  
  <p>Whatever the error occurred when I try to insert the record in database then it must be handled by the catch block but here it's not going happen.</p>