ErrorException.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://zjzit.cn>
  10. // +----------------------------------------------------------------------
  11. namespace think\exception;
  12. use think\Exception;
  13. /**
  14. * ThinkPHP错误异常
  15. * 主要用于封装 set_error_handler 和 register_shutdown_function 得到的错误
  16. * 除开从 think\Exception 继承的功能
  17. * 其他和PHP系统\ErrorException功能基本一样
  18. */
  19. class ErrorException extends Exception
  20. {
  21. /**
  22. * 用于保存错误级别
  23. * @var integer
  24. */
  25. protected $severity;
  26. /**
  27. * 错误异常构造函数
  28. * @param integer $severity 错误级别
  29. * @param string $message 错误详细信息
  30. * @param string $file 出错文件路径
  31. * @param integer $line 出错行号
  32. * @param array $context 错误上下文,会包含错误触发处作用域内所有变量的数组
  33. */
  34. public function __construct($severity, $message, $file, $line, array $context = [])
  35. {
  36. $this->severity = $severity;
  37. $this->message = $message;
  38. $this->file = $file;
  39. $this->line = $line;
  40. $this->code = 0;
  41. empty($context) || $this->setData('Error Context', $context);
  42. }
  43. /**
  44. * 获取错误级别
  45. * @return integer 错误级别
  46. */
  47. final public function getSeverity()
  48. {
  49. return $this->severity;
  50. }
  51. }