在用include加载某个文件时,被加载的文件有错误,可以用try-catch抛出异常吗? 异常include 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 require一个文件存在错误的话,那么程序就会中断执行了,并显示致命错误include一个文件存在错误的话,那么程序不会中端,而是继续执行,并显示一个警告错误。 include 可以用try-catch抛出及捕捉异常。<?phperror_reporting(0);try{ $flag = include "inc.php"; if(!$flag){ throw new Exception("include error", 1); }}catch(Exception $e){ echo "inc.php not exists<br>";}echo 'do sth';?> 如果使用require文件不存在,是fatal error,程序会中指。所以try-catch不适合。但可以用set_error_handle来设定出现错误后的处理动作。error_reporting(0);function handle($errno , $errstr , $errfile , $errline){ echo 'inc.php not exits<br>'; echo 'do sth';}set_error_handler('handle');require_once "inc.php"; 如果 inc.php 写作<?php错误能抛出及捕捉异常吗? 一个php的万年历中的数组不太理解。。 这段for语句的执行什么意思 传递控件变量 正则表达式表示文件名 谁用过php下面的tidy?有问题请教。[内详] javascript 传递php变量 我准备在单机上装个开发系统,要装什么东西? CSDN没有人才了?!我一个这么简单的问题都讨论了2天还没结果。 求教:新浪SAE能连其他数据库吗? 求救!请教大神 htaccess 伪静态规则问题 PHP ADODB 数据库操作 FOR循环
include一个文件存在错误的话,那么程序不会中端,而是继续执行,并显示一个警告错误。
error_reporting(0);try{
$flag = include "inc.php";
if(!$flag){
throw new Exception("include error", 1);
}
}catch(Exception $e){
echo "inc.php not exists<br>";
}echo 'do sth';
?>
但可以用set_error_handle来设定出现错误后的处理动作。error_reporting(0);function handle($errno , $errstr , $errfile , $errline){
echo 'inc.php not exits<br>';
echo 'do sth';
}set_error_handler('handle');require_once "inc.php";
错误能抛出及捕捉异常吗?