BaseException.php 861 B

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