BaseException.php 711 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace app\common\exception;
  3. use think\Exception;
  4. /**
  5. * Class BaseException
  6. * 自定义异常类的基类
  7. */
  8. class BaseException extends Exception
  9. {
  10. public $code = 0;
  11. public $message = 'invalid parameters';
  12. /**
  13. * 构造函数,接收一个关联数组
  14. * @param array $params 关联数组只应包含code、msg,且不应该是空值
  15. */
  16. public function __construct($params = [])
  17. {
  18. if (!is_array($params)) {
  19. return;
  20. }
  21. if (array_key_exists('code', $params)) {
  22. $this->code = $params['code'];
  23. }
  24. if (array_key_exists('msg', $params)) {
  25. $this->message = $params['msg'];
  26. }
  27. }
  28. }