Home > Backend Development > PHP Tutorial > 使用trigger_error如何没有显示自定义的异常信息

使用trigger_error如何没有显示自定义的异常信息

WBOY
Release: 2016-06-13 13:39:40
Original
1291 people have browsed it

使用trigger_error怎么没有显示自定义的错误信息

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--><?php function error($errorno,$errormes,$errorfile,$errorline){
$error_info="错误信息:".$errorno."--".$errormes." in ".$errorfile." on line ".$errorline;
echo $error_info;
date_default_timezone_set("PRC");
error_log("时间:".date("Y-m-d H:i:s")."-".$error_info."\r\n",3,"error_log.txt");
die();
}
set_error_handler(error);
$fp=fopen("aa.txt","r");
if(!$fp){
trigger_error("文件打不开");

}
else{

echo"kai";
}
Copy after login


运行后提示:
错误信息:2--fopen(aa.txt) [function.fopen]: failed to open stream: No such file or directory in D:\AppServ\www\test.php on line 10
为什么错误信息“fopen(aa.txt) [function.fopen]: failed to open stream: No such file or directory ”不是我用trigger_error定义的“文件打不开”,应该怎么改

------解决方案--------------------
set_error_handler(error);
===>
set_error_handler("error");
------解决方案--------------------
确认文件及路径正确了? 当前目录下有aa.txt文件吗?
------解决方案--------------------
trigger_error("不能存在", E_USER_ERROR);

通常
trigger_error()
set_error_handler('error_handler');
是配合使用,一个抛出,一个接受,处理
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