For more details and usage information on ErrorException, see the guide article on handling errors.
Since: 2.0
Author: Alexander Makarov (sam@rmcreative.ru)
Inheritance: extends ErrorException
 /**
  * Constructs the exception.
  * @link http://php.net/manual/en/errorexception.construct.php
  * @param $message [optional]
  * @param $code [optional]
  * @param $severity [optional]
  * @param $filename [optional]
  * @param $lineno [optional]
  * @param $previous [optional]
  */
 public function __construct($message = '', $code = 0, $severity = 1, $filename = __FILE__, $lineno = __LINE__, \Exception $previous = null)
 {
     parent::__construct($message, $code, $severity, $filename, $lineno, $previous);
     if (function_exists('xdebug_get_function_stack')) {
         $trace = array_slice(array_reverse(xdebug_get_function_stack()), 3, -1);
         foreach ($trace as &$frame) {
             if (!isset($frame['function'])) {
                 $frame['function'] = 'unknown';
             }
             // XDebug < 2.1.1: http://bugs.xdebug.org/view.php?id=695
             if (!isset($frame['type']) || $frame['type'] === 'static') {
                 $frame['type'] = '::';
             } elseif ($frame['type'] === 'dynamic') {
                 $frame['type'] = '->';
             }
             // XDebug has a different key name
             if (isset($frame['params']) && !isset($frame['args'])) {
                 $frame['args'] = $frame['params'];
             }
         }
         $ref = new \ReflectionProperty('Exception', 'trace');
         $ref->setAccessible(true);
         $ref->setValue($this, $trace);
     }
 }
示例#2
0
 /**
  * Filter all exceptions. They're logged via ErrorHandler
  * @inheritdoc
  */
 public static function filterMessages($messages, $levels = 0, $categories = [], $except = [])
 {
     $messages = parent::filterMessages($messages, $levels, $categories, $except);
     foreach ($messages as $i => $message) {
         $type = explode(':', $message[2]);
         // shutdown function not working in yii2 yet: https://github.com/yiisoft/yii2/issues/6637
         // allow fatal errors exceptions in log messages
         if (is_array($type) && sizeof($type) == 2 && $type[0] == 'yii\\base\\ErrorException' && ErrorException::isFatalError(['type' => $type[1]])) {
             continue;
         }
         if (is_string($message[0]) && strpos($message[0], 'exception \'') === 0) {
             unset($messages[$i]);
         }
     }
     return $messages;
 }
示例#3
0
 /**
  * Handles fatal PHP errors
  */
 public function handleFatalError()
 {
     unset($this->_memoryReserve);
     // load ErrorException manually here because autoloading them will not work
     // when error occurs while autoloading a class
     if (!class_exists('yii\\base\\ErrorException', false)) {
         require_once __DIR__ . '/ErrorException.php';
     }
     $error = error_get_last();
     if (ErrorException::isFatalError($error)) {
         if (!empty($this->_hhvmException)) {
             $exception = $this->_hhvmException;
         } else {
             $exception = new ErrorException($error['message'], $error['type'], $error['type'], $error['file'], $error['line']);
         }
         $this->exception = $exception;
         $this->logException($exception);
         if ($this->discardExistingOutput) {
             $this->clearOutput();
         }
         $this->renderException($exception);
         // need to explicitly flush logs because exit() next will terminate the app immediately
         Yii::getLogger()->flush(true);
         if (defined('HHVM_VERSION')) {
             flush();
         }
         exit(1);
     }
 }
示例#4
0
 /**
  * 处理 PHP 致命错误
  */
 public function handleFatalError()
 {
     unset($this->_memoryReserve);
     // load ErrorException manually here because autoloading them will not work
     // when error occurs while autoloading a class
     if (!class_exists('yii\\base\\ErrorException', false)) {
         require_once __DIR__ . '/ErrorException.php';
     }
     $error = error_get_last();
     if (ErrorException::isFatalError($error)) {
         $exception = new ErrorException($error['message'], $error['type'], $error['type'], $error['file'], $error['line']);
         $this->exception = $exception;
         // use error_log because it's too late to use Yii log
         // also do not log when on CLI SAPI because message will be sent to STDERR which has already been done by PHP
         PHP_SAPI === 'cli' or error_log($exception);
         if ($this->discardExistingOutput) {
             $this->clearOutput();
         }
         $this->renderException($exception);
         exit(1);
     }
 }
 /**
  * Handles fatal PHP errors
  */
 public function handleFatalError()
 {
     unset($this->_memoryReserve);
     // load ErrorException manually here because autoloading them will not work
     // when error occurs while autoloading a class
     if (!class_exists('\\yii\\base\\Exception', false)) {
         require_once __DIR__ . '/Exception.php';
     }
     if (!class_exists('\\yii\\base\\ErrorException', false)) {
         require_once __DIR__ . '/ErrorException.php';
     }
     $error = error_get_last();
     if (ErrorException::isFatalError($error)) {
         $exception = new ErrorException($error['message'], $error['type'], $error['type'], $error['file'], $error['line']);
         $this->exception = $exception;
         // use error_log because it's too late to use Yii log
         error_log($exception);
         if (($handler = $this->getErrorHandler()) !== null) {
             $handler->handle($exception);
         } else {
             echo $this->renderException($exception);
         }
         exit(1);
     }
 }