title: Handling database errors
body: <p>I am using an MVC framework in my application, so currently when I detect an error has occurred while working with the database in my model, I am throwing exceptions back to the controller.</p>
  
  <pre><code>//db querying
  //doing more db querying...
  if (error)
      throw new ApiException('Unable to connect to User database', 1, 500);
  else if (another type of error)
      throw new StampApiException('Could not retrieve the User', 12, 500);
  
  return $user;
  </code></pre>
  
  <p>Most of the time I find this to be nice as I can just have the controller print the error to the screen, thus keeping all error codes etc... in the model. But at times this can make the code quite messy and harder to deal with.</p>
  
  <p>Is this a good way to be handling such errors? Or is there a better/more standard way?</p>