title: Custom Error in Active Record Codeigniter
body: <p>I am using HMVC. My question is very simple. how we can catch the error in active records?
  how we can return custom error to controller from model(active records)?</p>
  
  <p>Actually, msn column is unique so, when i enter duplicate value then its show error like</p>
  
  <p>Error Number: 1062</p>
  
  <p>Duplicate entry '3696003284' for key 'msn'</p>
  
  <p>but i want to show custom error instead of this.</p>
  
  <p>my simple code is:</p>
  
  <pre><code>function insert_data($msn_number, $date_val, $min_val, $max_val, $avg_val,$counter)
  {
      for($i=0;$i&lt;$counter;$i++)
      {
          $data = array(
              'msn'     =&gt; $msn_number[$i],
              'date'    =&gt; $date_val[$i],
              'min_val' =&gt; $min_val[$i],
              'max_val' =&gt; $max_val[$i],
              'average' =&gt; $avg_val[$i]
          );
          $result = $this-&gt;db-&gt;insert('storage_data', $data);
          if(!isset($result))
           {
             echo "custom Error";
            }
  
      }
   }
  </code></pre>
  
  <p>}</p>
  
  <p>i am wondering for the answer of this question please help me!</p>