public function __construct($message = '', $code = 0, $previous = null, $file = null, $line = null) { if (!is_numeric($code)) { $message = 'Error code: ' . $code . '; ' . $message; $code = -1; } parent::__construct($message, $code, $previous); !is_null($file) and $this->file = $file; !is_null($line) and $this->line = $line; $info = array(); $app =& self::$app; //设置错误信息 $info['time'] = date('Y-m-d H:i:s', $app->TIME); $info['title'] = isset(self::$errorTitle[$this->getCode()]) ? self::$errorTitle[$this->getCode()] : '应用程序错误'; $info['code'] = $this->getCode(); $info['file'] = $this->file; $info['line'] = $this->line; $info['message'] = $this->getMessage(); $info['path'] = $app->request()->getUri(); $info['ip'] = $app->request()->getIP(); $info['backtrace'] = $this->getTraceAsString(); //记录日志 !$app->DEBUG and $app->logger()->error($info); //显示错误 $this->showError($info); }
/** * 设置错误管理器 */ protected function setError() { Exceptions\Exception::$app = $this; Exceptions\Exception::$errorReporting = $this->errorReporting(); //接管错误和异常处理 error_reporting($this->DEBUG); //注册系统默认异常处理函数 //set_exception_handler(array($this, 'exceptionHandler')); set_exception_handler(function (\Exception $e) { throw new Exceptions\Exception($e->getMessage(), $e->getCode(), $e->getPrevious(), $e->getFile(), $e->getLine()); }); //注册系统默认错误处理函数 //set_error_handler(array($this, 'errorHandler'), $this->DEBUG); set_error_handler(function ($code = 0, $message = '', $file = null, $line = null) { throw new Exceptions\Exception($message, $code, null, $file, $line); }, $this->DEBUG); }
/** * construct method * * @param string $message error message * @param int $code error code * * @return \Monkey\Exceptions\Http\Base */ public function __construct($message = '', $code = -1) { $code == -1 and $code = $this->statusCode; parent::__construct($message, $code); }