title: Error Handling in PHP. How to do it?
body: <p>I'm a beginner in PHP OOP and I'm with some doubts about the correct way of handling errors in PHP.</p>
  
  <p>Look at this function for example:</p>
  
  <pre><code>public function deleteFileFromDisk($fileNameToBeDeleted) {
  
      $handle = unlink($fileNameToBeDeleted);
  
      if (!$handle) {
          $result = "(this-&gt;deleteFileFromDisk) - Error, " . $fileNameToBeDeleted . " not deleted.";
      } else {
          $result = "(this-&gt;deleteFileFromDisk) - Success, " . $fileNameToBeDeleted . " deleted.";
      }
      return $result;
  }
  </code></pre>
  
  <p>Is this the correct way of doing it, or I can do better than this?</p>
  
  <p>Let me add some details of what I'm achieving...</p>
  
  <p>I'm running class methods, and I need to control errors in the process. If any call to the object throw an error I need to catch it and send an e-mail.</p>
  
  <p>Here are the object interactions:</p>
  
  <pre><code>$testar_classe = new geoIpImportCSV('geolitecity', 'http://geolite.maxmind.com/download/geoip/database/GeoLiteCity_CSV/');
  $testar_classe-&gt;downloadAndSaveFile('./', $testar_classe-&gt;obtainDownloadFileName());
  $testar_classe-&gt;uncompressZipFile($testar_classe-&gt;obtainDownloadFileName(), '.');
  $testar_classe-&gt;deleteLine(1, 'GeoLiteCity-Location.csv');               
  $testar_classe-&gt;deleteLine(1, 'GeoLiteCity-Blocks.csv');
  $testar_classe-&gt;deleteDataFromTable('tabela1');
  $testar_classe-&gt;deleteDataFromTable('tabela2');
  $testar_classe-&gt;insertLinesToDb('GeoLiteCity-Location.csv', 'tabela1');
  $testar_classe-&gt;insertLinesToDb('GeoLiteCity-Blocks.csv', 'tabela2');
  $testar_classe-&gt;deleteFileFromDisk($testar_classe-&gt;obtainDownloadFileName());
  $testar_classe-&gt;deleteFileFromDisk('GeoLiteCity-Blocks.csv');
  $testar_classe-&gt;deleteFileFromDisk('GeoLiteCity-Location.csv'); 
  </code></pre>
  
  <p>Which is the best way of handle this? Create a new method to take care of the exceptions? There are any examples on how to do this?</p>
  
  <p>Best Regards.</p>