国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

33.錯誤處理(2)

2019-11-08 01:59:20
字體:
來源:轉載
供稿:網友

這里寫圖片描述

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兩個函數,如果沒有這兩個函數的調用,那么在后續的錯誤處理過程中,當再次產生異?;蚴清e誤時,又會調用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.使用一個動作來處理錯誤 這里寫圖片描述 這里寫圖片描述 這里寫圖片描述


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 永嘉县| 定日县| 清河县| 辉县市| 叶城县| 孝感市| 交口县| 茶陵县| 台湾省| 东丰县| 揭东县| 苏尼特右旗| 古蔺县| 依安县| 徐州市| 凤台县| 南丰县| 漳平市| 桦甸市| 湘西| 精河县| 凭祥市| 嘉兴市| 沙洋县| 山东| 崇仁县| 大足县| 博湖县| 阿城市| 凤凰县| 金塔县| 收藏| 江北区| 商洛市| 达尔| 桂平市| 北辰区| 晋江市| 沙雅县| 旌德县| 蓬溪县|