大佬教程收集整理的这篇文章主要介绍了php-对我的框架实施错误处理,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
class Core_Error_Exception
{
var $previus_error_level,$captured_contents;
private $stack_trace = array();
public function Core_Error_Exception()
{
$this->previus_error_level = error_reporTing(-1);
set_error_handler(array($this,'_collect_error'));
set_exception_handler(array($this,'_collect_error'));
ob_start(array($this,'_capture'));
}
public function _collect_error($errno, $errstr, $errfile, $errline, $context)
{
$this->stack_trace[] = array(
array('name' => 'Error ID:', 'value' => $errno),
array('name' => 'Error String:','value' => $errstr),
array('name' => 'Error File:', 'value' => $errfilE),
array('name' => 'Error Line:', 'value' => $errlinE),
array('name' => 'Context PRE:', 'value' => $context)
);
var_dump($this->stack_tracE);
}
/*
* _capture is used to capture pre_bufferd content.
*/
public function _capture($content,$bitfeild)
{
if($bitfeild & PHP_OUTPUT_HANDLER_START)
{
$this->captured_contents = $content;
}
if($bitfeild & PHP_OUTPUT_HANDLER_CONT)
{
$this->captured_contents .= $content;
}
if($bitfeild & PHP_OUTPUT_HANDLER_END)
{
$this->captured_contents .= $content;
}
return false;
}
}
@H_616_0@因此,我想做的是能够以防跌倒的方式构造此类,以便将可能已触发的任何通知错误放入数组中,如果调用了E_ERROR通知,则此操作会自动运行在那一刻下来,以防止引起更多的错误.
@H_616_0@我将使用一个小的html模板处理程序,在其中可以传递该上下文错误集,因此请注意错误和单个E _ * _ ERROR(如果适用).
@H_616_0@与过去一样,构建此类的最佳方法是什么?我在执行错误跟踪/报告时遇到了一些困难.
@H_616_0@更新:当前课程
@H_616_0@如果触发了错误,例如trigger_error(‘test’,XXX);我希望能够跟踪所有错误,直到应用程序启动或触发了E_user_ERROR.
@H_616_0@有时我很难完全掌握PHP的错误系统,等等,有时我对如何构建它感到困惑,以至于它不易摔倒.解决方法:
@H_616_0@我不太确定自己在做什么,但是最直接的方法是按照以下方式使用嵌套的try块: @H_616_0@in Class Application:
function run() {
try {
--do stuff
} catch(AppException $E) {
-- handle application-level exception
}
-- all other exceptions fall through
in Class Core:
try {
$core->init();
$application->run(); <-- calls the above function
$core->done();
} catch(Exception $E) {
--last chance exception handler
--process exceptions the Application was unable to handle on its own
}
@H_616_0@为了能够以这种方式捕获PHP内置错误或trigger_error事件,还应该始终安装errors-to-exceptions handler.以上是大佬教程为你收集整理的php-对我的框架实施错误处理全部内容,希望文章能够帮你解决php-对我的框架实施错误处理所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。