我正在尝试在我的模型和控制器中使用异常。在application
, 目录中,我创建了一个目录Exceptions
,其中包含文件“CustomException1.php”和“CustomException2.php”中的一些异常类。
我定义MY_Controller
在application/core
class MY_Controller extends CI_Controller {
public function __construct() {
parent::__construct();
// include Exception files
require_once(APPPATH . 'Exceptions/CustomException1.php');
require_once(APPPATH . 'Exceptions/CustomException2.php');
}
}
在我的控制器中Test
:
class Test extends MY_Controller {
public function index() {
try {
throw new CustomException1('This is a custom exception');
} catch (CustomException1 $e) {
$this->output->set_status_header('500');
echo $e->message;
}
}
现在,我希望这可以工作,因为我需要定义异常类的所有文件,但我仍然收到一条错误消息
Class CustomException1 not found on line xx