lopes_andre Posted December 22, 2010 Share Posted December 22, 2010 Hi, I'm testing Exceptions in PHP. But I'm not getting this to work. Please see the code. $testar_classe = new geoIpImportCSV('geolitecity', 'http://geolite.maxmind.com/download/geoip/database/GeoLiteCity_CSV/'); // Bloco Try/Catch try { echo $testar_classe->deleteFileFromDisk('GeoLiteCity-Location.csv'); } catch (Exception $e) { echo $e->getMessage; } I'm running the code above passing to the method "deleteFileFromDisk" a parameter with a wrong name to show the Exception. The method that I'm calling have this code: public function deleteFileFromDisk($fileNameToBeDeleted) { // Apagar ficheiro $handle = unlink($fileNameToBeDeleted); // Fazer a verificação de excepções if (!$handle) { // Passou-se algo e o ficheiro n foi apagado. throw new Exception("Nao foi possivel apagar o ficheiro. (this->deleteFileFromDisk) - " . $fileNameToBeDeleted); } // Correu tudo bem, vou sair return TRUE; } What I'm doing wrong? This Exception does not catch wrong filenames passed to the parameter? The result of running the code is this: Warning: unlink(GeoLiteCity-Location.csv): No such file or directory in C:\xampp \htdocs\testes\testecsv4.php on line 295 Give some clues. Best Regards Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted December 22, 2010 Share Posted December 22, 2010 i am not very experienced with exception handling, but have you tried this? // Fazer a verificação de excepções if (!unlink($fileNameToBeDeleted)) { // Passou-se algo e o ficheiro n foi apagado. throw new Exception("Nao foi possivel apagar o ficheiro. (this->deleteFileFromDisk) - " . $fileNameToBeDeleted); } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.