Home > Backend Development > PHP Tutorial > PHP如何捕捉include_once的异常

PHP如何捕捉include_once的异常

WBOY
Release: 2016-06-13 13:19:40
Original
1126 people have browsed it

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后再处理...

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template