添加Error异常的ErrorContext参数,并打印ErrorContext到异常页面

This commit is contained in:
麦当苗儿
2016-02-02 10:36:03 +08:00
parent dfa756f181
commit 89942815f6
2 changed files with 6 additions and 3 deletions

View File

@@ -89,14 +89,14 @@ class Error
* @param integer $errline 出错行号 * @param integer $errline 出错行号
* @return bool true-禁止往下传播已处理过的异常 * @return bool true-禁止往下传播已处理过的异常
*/ */
public static function appError($errno, $errstr, $errfile, $errline) public static function appError($errno, $errstr, $errfile = null, $errline = 0, array $errcontext = [])
{ {
if ($errno & Config::get('exception_ignore_type')) { if ($errno & Config::get('exception_ignore_type')) {
// 忽略的异常记录到日志 // 忽略的异常记录到日志
Log::record("[{$errno}]{$errstr}[{$errfile}:{$errline}]", 'notic'); Log::record("[{$errno}]{$errstr}[{$errfile}:{$errline}]", 'notic');
} else { } else {
// 将错误信息托管至 think\exception\ErrorException // 将错误信息托管至 think\exception\ErrorException
throw new ErrorException($errno, $errstr, $errfile, $errline); throw new ErrorException($errno, $errstr, $errfile, $errline, $errcontext);
// 禁止往下传播已处理过的异常 // 禁止往下传播已处理过的异常
return true; return true;
} }

View File

@@ -33,14 +33,17 @@ class ErrorException extends Exception
* @param string $message 错误详细信息 * @param string $message 错误详细信息
* @param string $file 出错文件路径 * @param string $file 出错文件路径
* @param integer $line 出错行号 * @param integer $line 出错行号
* @param array $context 错误上下文,会包含错误触发处作用域内所有变量的数组
*/ */
public function __construct($severity, $message, $file, $line) public function __construct($severity, $message, $file, $line, $context)
{ {
$this->severity = $severity; $this->severity = $severity;
$this->message = $message; $this->message = $message;
$this->file = $file; $this->file = $file;
$this->line = $line; $this->line = $line;
$this->code = 0; $this->code = 0;
empty($context) || $this->setData('Error Context', $context);
} }
/** /**