title: error handling in codeigniter: who should call show_error()
body: <p>I have a question about error handling in codeigniter. 
  My first question is who should call the show_error method?  The model or the controller or the view? 
  I was going to put it in the model for this particular case because the model is where the error is generated, but since most of my business logic is in the controller I decided to do it there.  BUt I'd like to know if there is a "correct" way to do this. </p>
  
  <p>My second question is this.  In the model, i have added two functions- one to return data, and the other to return an error message.  My controller tests for an error condition after calling my model, and attempts to display it.  But its always empty.</p>
  
  <p>My model looks something like this: </p>
  
  <pre><code>    public function errormessage()
      {
          return $this-&gt;_emess;
      }
      public someotherfunction()
      {
           if ( $switch_obj-&gt;connect() )
          {
              $retdata = $switch-&gt;showInterfaceAll(); 
              $switch-&gt;disconnect();  
              $this-&gt;_data = $retdata;
              return true;
          }
          else
          {
              print 'debug: assigning error message in model:';
              $this-&gt;_emess = $switch-&gt;errormessage();
              print $this-&gt;_emess;
              return false;
          }
            }
  </code></pre>
  
  <p>Then in my controller, i have the following logic: </p>
  
  <pre><code>      if ($this-&gt;switches_model-&gt;someotherfunction($this-&gt;uri-&gt;segment(7) ) )
        {      
        $data['listofports'] = $this-&gt;switches_model-&gt;data;
        }
        else {
                print '&lt;BR&gt;in error path&lt;BR&gt;';
        show_error($this-&gt;switches_model-&gt;errormessage(), 123);
        }
  </code></pre>
  
  <p>From my debug print statements in the model, i know that an error message has been set.  But by the time the controller tries to display it using the show_error() method, i'm getting the following error message: </p>
  
  <blockquote>
    <p>No status text available. Please check your status code number or
    supply your own message text.</p>
  </blockquote>
  
  <p>To prove that its not because the model has already been destroyed, I tried adding a destructor in my model and printing out a debug line...</p>
  
  <pre><code>    public function __destruct()
      {
        print 'in the destructor';
      }
  </code></pre>
  
  <p>The message "in error path" is printed before "in the destructor" so I'm assuming that the model is still alive and well...</p>
  
  <p>Any suggestions would be appreciated. </p>
  
  <p>Thanks. </p>
  
  <p><strong>UPDATE 1</strong></p>
  
  <p>I found my problem.  You need to pass a legit status code, if you're going to pass one at all. 
  I thought you could create custom status numbers, but they must be HTTP codes.  But if someone could comment on question 1 about who should call show_error() that'd be much appreciated.
  Thanks. </p>