PHP rename()不会在错误时抛出异常 [英] PHP rename() doesn't throws exception on error
本文介绍了PHP rename()不会在错误时抛出异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用php应用程序,并且有一行移动文件。我在try ... catch块中包含了方法,所以如果抛出一个错误,可以管理回滚系统。但是异常从未被捕获,所以重命名会引发任何异常?
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?
感谢
上面的代码:
try{
if(rename($archivo_salida, $ruta_archivos)){
//anything;
}
}catch (Exception $e)
//do something
}
推荐答案
正常PHP函数不抛出异常。
"Normal" PHP functions don't throw exceptions.
更改代码以模拟异常:
try{
if(rename($archivo_salida, $ruta_archivos)){
//anything;
} else {
throw new Exception('Can not rename file'.$archivo_salida);
}
}catch (Exception $e)
//do something
}
这篇关于PHP rename()不会在错误时抛出异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文