Exception.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2006~2021 http://thinkphp.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: liu21st <liu21st@gmail.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace think;
  13. /**
  14. * 异常基础类
  15. * @package think
  16. */
  17. class Exception extends \Exception
  18. {
  19. /**
  20. * 保存异常页面显示的额外Debug数据
  21. * @var array
  22. */
  23. protected $data = [];
  24. /**
  25. * 设置异常额外的Debug数据
  26. * 数据将会显示为下面的格式
  27. *
  28. * Exception Data
  29. * --------------------------------------------------
  30. * Label 1
  31. * key1 value1
  32. * key2 value2
  33. * Label 2
  34. * key1 value1
  35. * key2 value2
  36. *
  37. * @access protected
  38. * @param string $label 数据分类,用于异常页面显示
  39. * @param array $data 需要显示的数据,必须为关联数组
  40. */
  41. final protected function setData(string $label, array $data)
  42. {
  43. $this->data[$label] = $data;
  44. }
  45. /**
  46. * 获取异常额外Debug数据
  47. * 主要用于输出到异常页面便于调试
  48. * @access public
  49. * @return array 由setData设置的Debug数据
  50. */
  51. final public function getData()
  52. {
  53. return $this->data;
  54. }
  55. }