设为首页 加入收藏

TOP

php中设定一个全局异常处理。全局catch。默认catch。默认异常处理
2017-10-10 12:02:16 】 浏览:3114
Tags:php 设定 一个 全局 异常 处理 catch 默认
 1 <?php
 2 
 3     function handleMissedException($e) {
 4             echo "Sorry, something is wrong. Please try again, or contact us if the problem persists. Thanks!";
 5             //error_log($str);//保存一条错误信息字符串到web服务器的error_log文档里。
 6             error_log('Unhandled Exception:' . $e->getMessage() . 'in file' . $e->getFile() . 'on line' . $e->getLine());
 7     }
 8 
 9     set_exception_handler('handleMissedException');
10 
11     //测试抛出一个错误。
12     throw new Exception('just testing');
13 
14     //整个测试程序就这么多。
15     //上下文都没有catch。所以会触发 handleMissedExceotion($e)函数, $e为Exception或Exception的子类

error_log存在web服务器的error_log里。

例如:apache可以在配置文件httpd.conf中搜error_log找到它的位置。

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇php中的抛出异常和捕捉特定类型的.. 下一篇centos+php+coreseek+sphinx+mysq..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目