PHP rename() doesn't throws exception on error

exception, php

Solution

"Normal" PHP functions don't throw exceptions.

Change your code to simulate an exception:

try {
   if (rename($archivo_salida, $ruta_archivos)) {
      //anything;
   } else {
      throw new Exception('Can not rename file'.$archivo_salida);
   }
} catch (Exception $e) {
   //do something, such as
   echo 'Caught exception: ',  $e->getMessage(), "\n";
}

Problem

I'm working with a php application, and there is a line that moves a file. I enclosed the method within a try...catch block so, if a error is thrown, can manage a rollback system. But the exception is never catched, so, renames throws any kind of exception? Do I need to try with another method? Thanks Code above: ``` try{ if(rename($archivo_salida, $ruta_archivos)){ //anything; } }catch (Exception $e) //do something } ```

Original source

Related problems