33.错误处理(2)
来源:互联网 发布:删除sql server 2008 编辑:程序博客网 时间:2024/05/17 23:50
1.错误处理
发生错误后引发 handleError() 函数处理:public function handleError($code,$message,$file,$line) { if($code & error_reporting()) { // disable error capturing to avoid recursive errors restore_error_handler(); restore_exception_handler(); //restore_error_handler,restore_exception_handler两个函数,如果没有这两个函数的调用,那么在后续的错误处理过程中,当再次产生异常或是错误时,又会调用CApplication:: handleError ,从而可能造成死循环,故Yii在此处临时禁止了使用CApplication:: handleError 接管后续的错误和异常(使用php默认的错误处理机制),这就保证了不会因之产生循环调用。 $log="$message ($file:$line)\nStack trace:\n"; $trace=debug_backtrace(); // skip the first 3 stacks as they do not tell the error position if(count($trace)>3) { $trace=array_slice($trace,3); } foreach($trace as $i=>$t) { if(!isset($t['file'])) { $t['file']='unknown'; } if(!isset($t['line'])) { $t['line']=0; } if(!isset($t['function'])) { $t['function']='unknown'; } $log.="#$i {$t['file']}({$t['line']}): "; if(isset($t['object']) && is_object($t['object'])) { $log.=get_class($t['object']).'->'; } $log.="{$t['function']}()\n"; } if(isset($_SERVER['REQUEST_URI'])) { $log.='REQUEST_URI='.$_SERVER['REQUEST_URI']; } Yii::log($log,CLogger::LEVEL_ERROR,'php'); try { Yii::import('CErrorEvent',true); $event=new CErrorEvent($this,$code,$message,$file,$line); //此时将产生一个CErrorEvent(并包含$code,$message,$file,$line几项关键参数), 传递给CErrorHandler组件进行处理。具体是交给CErrorHandler::handleError处理之 。这个流程主要是将错误相关信息进行整理,并以合适的方式进行显示。 $this->onError($event); if(!$event->handled) { // try an error handler if(($handler=$this->getErrorHandler())!==null) { $handler->handle($event); } else { $this->displayError($code,$message,$file,$line); } } } catch(Exception $e) { $this->displayException($e); } try { $this->end(1); } catch(Exception $e) { // use the most primitive way to log error $msg = get_class($e).': '.$e->getMessage().' ('.$e->getFile().':'.$e->getLine().")\n"; $msg .= $e->getTraceAsString()."\n"; $msg .= "Previous error:\n"; $msg .= $log."\n"; $msg .= '$_SERVER='.var_export($_SERVER,true); error_log($msg); exit(1); } } }
2.异常处理
3.使用一个动作来处理错误
0 0
- 33.错误处理(2)
- javascript错误处理(2)
- Tibco 平台的错误处理 2, 错误集中处理
- xcode4.2 ARC错误处理
- 错误处理
- 错误处理
- 错误处理
- 处理错误
- 错误处理
- 错误处理
- 错误处理
- 错误处理
- 错误处理
- 错误处理
- 错误处理
- 错误处理
- 错误处理
- 错误处理
- python的strip(),lstrip()和rstrip()
- 整合CKEditor和CKFinder(for java)
- 小程序基础组件与导航组件
- stm32 Can通讯过滤器寄存器设置(实验验证)
- loadrunner连接数据库脚本
- 33.错误处理(2)
- c++学习笔记——虚函数(virtual function)
- Arduino简单实例之九_温湿度传感器模块
- 值得拥有的Windows系统链接及哈希验证码
- 标准C++中的string类的用法总结
- QML-例程photosurface
- DJango+UWSgi+Nginx部署
- Zookeeper的java客户端API使用方法(五)
- ThreadPoolExcutor详解