Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

48 righe
1.5 KiB

  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. }