我想在文件不存在的情况下使用异常处理。例如,当我运行模型方法并传递字符串usr(我知道没有该名称的文件)。它给我以下错误信息如何检查文件是否存在异常handeling
Fatal error: Uncaught exception 'Exception' with message 'Usr.php was not found' in /app/core/controller.php on line 14
我不明白这里有什么错。有人可以帮我解决这个问题吗?
以下是我的代码。非常感谢!
class Controllers{
public function model($model){
if(!file_exists("../app/models/".$model.".php")) {
throw new exception("{$model}.php was not found");
}
try {
require ("../app/models/".$model.".php");
} catch(Exception $e) {
echo $e->getMessage();
}
return new $model();
}
}
啊我看到在文件中使用try/catch块。这是一个很好的做法。谢谢!!! – elrado88 2014-09-27 13:47:16