在用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错误能抛出及捕捉异常吗? 多级菜单的制作 move_uploaded_file 上传文件目录权限被改变,怎么办 关于excelreader读取excel乱码的问题 php分页置顶到第二页 发起关于php的大学习,大讨论..... php setcookie失败 关于两个表数据调出和检索的问题! 浙江嘉兴市急招!5名PHP高级网络工程师 月薪5千,可再面议 PHP在IIS6下运行会出现" HTTP 服务器终止了该脚本"请大家帮着看看。 如何写这个sql语句?更新表的 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";
错误能抛出及捕捉异常吗?