当前位置:Gxlcms > PHP教程 > PHP如何捕捉include_once的异常

PHP如何捕捉include_once的异常

时间:2021-07-01 10:21:17 帮助过:5人阅读

PHP怎么捕捉include_once的错误?
PHP怎么捕捉include_once和require_once的错误?

如果文件不存在,或文件中有编译等其它错误等,可捕捉吗?

DEMO:
try{
include_once( "t/ttt.php ");
}catch(Exception $e) {
echo 'Caught exception: '.$e-> getMessage();
}


------解决方案--------------------
可以这样变通一点:
if(!file_exists( "t/ttt.php "))
{
include_once( "t/ttt.php ");
}
require_once出错是编译时错误,不是RUNTIME的,应该抓不住错误的。
------解决方案--------------------
文件不存在可以用file_exists()来检查
文件程序错误可以使用isset,is_系列函数来检查某些核心变量的情况

------解决方案--------------------
帮顶了
不会捕抓
只会看错误报告
------解决方案--------------------
顶下,错误报告都不会,每次就用require_once,这样出错了就看页面的出错提示了!
------解决方案--------------------
file_exists后再处理...

人气教程排行