BusinessException.php 1018 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace app\common\exception;
  3. use Exception;
  4. /**
  5. * 业务异常类
  6. * 用于服务层抛出业务相关的异常
  7. */
  8. class BusinessException extends Exception
  9. {
  10. /**
  11. * 错误码
  12. * @var int
  13. */
  14. protected $errorCode;
  15. /**
  16. * 错误数据
  17. * @var mixed
  18. */
  19. protected $errorData;
  20. /**
  21. * 构造函数
  22. * @param string $message 错误消息
  23. * @param int $errorCode 错误码,默认为0
  24. * @param mixed $errorData 错误相关数据
  25. */
  26. public function __construct($message = '', $errorCode = 0, $errorData = null)
  27. {
  28. $this->errorCode = $errorCode;
  29. $this->errorData = $errorData;
  30. parent::__construct($message, $errorCode);
  31. }
  32. /**
  33. * 获取错误码
  34. * @return int
  35. */
  36. public function getErrorCode()
  37. {
  38. return $this->errorCode;
  39. }
  40. /**
  41. * 获取错误数据
  42. * @return mixed
  43. */
  44. public function getErrorData()
  45. {
  46. return $this->errorData;
  47. }
  48. }