title: When should I throw an exception as opposed to return an error in PHP?
body: <p>I'm working on an API wrapper class, which is the first I've made.
  For the most part it hasn't been too difficult.
  Getting to the point where I need to deal with the potential of errors being returned by the API, however confused as to how I should go about dealing with them.</p>
  
  <p>An external file will make a call to the API class, ie, <code>findVenueByLocationID($locationID);</code>
  This function will then construct the URL and method of API call (POST, GET, DELETE, etc) and pass that to a function called makeCall.</p>
  
  <p>MakeCall constructs the completed URL, sends the request to the service and passes back the resulting XML. If the API returns an error, it is within the XML it returns. The URL is called using the function file_get_contents(). The API has a set number of error codes it will return in the XML.</p>
  
  <p>As I understand it, I should do the following during the function makeCall: </p>
  
  <ul>
  <li>Before the XML is returned, check to see if it contains an error code, and if so, pass that to an error handling class to deal with the error. (Log and return client version error message)</li>
  <li>add a try catch around the file_get_contents() function to catch any connection errors, ie not being able to access the server?</li>
  </ul>
  
  <p>Is that considered the best way to do things?
  Should I be adding a try catch around the call to makeCall rather than inside it round file_get_contents?
  Should I be throwing an exception for each error returned by the XML and handling them with an error class?</p>
  
  <p>The sort of answer I'm looking for should also contain a link to a resource explaining some best practices surrounding error handling with API wrappers or such things.</p>
  
  <p>Thanks in advance for your time and responses.</p>
  
  <hr>
  
  <p>EDIT:
  After talking with our CTO, errors in PHP at current version ARE exceptions, and I should throw exceptions and leave the dealing of the exceptions to the caller. Remember, I'm implementing a wrapper class for an API. Thoughts?</p>