No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ThrowableError.php 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: yunwuxin <448901948@qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace think\exception;
  12. class ThrowableError extends \ErrorException
  13. {
  14. public function __construct(\Throwable $e)
  15. {
  16. if ($e instanceof \ParseError) {
  17. $message = 'Parse error: ' . $e->getMessage();
  18. $severity = E_PARSE;
  19. } elseif ($e instanceof \TypeError) {
  20. $message = 'Type error: ' . $e->getMessage();
  21. $severity = E_RECOVERABLE_ERROR;
  22. } else {
  23. $message = 'Fatal error: ' . $e->getMessage();
  24. $severity = E_ERROR;
  25. }
  26. parent::__construct(
  27. $message,
  28. $e->getCode(),
  29. $severity,
  30. $e->getFile(),
  31. $e->getLine()
  32. );
  33. $this->setTrace($e->getTrace());
  34. }
  35. protected function setTrace($trace)
  36. {
  37. $traceReflector = new \ReflectionProperty('Exception', 'trace');
  38. $traceReflector->setAccessible(true);
  39. $traceReflector->setValue($this, $trace);
  40. }
  41. }