You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

CommonBizException.java 1.1 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package com.xkcoding.common.exception;
  2. import com.xkcoding.common.enums.CommonStatus;
  3. import com.xkcoding.common.enums.base.IStatus;
  4. import lombok.Data;
  5. import lombok.EqualsAndHashCode;
  6. /**
  7. * 通用业务异常
  8. *
  9. * @author yangkai.shen
  10. * @date 2022-08-20 01:55
  11. */
  12. @Data
  13. @EqualsAndHashCode(callSuper = true)
  14. public class CommonBizException extends RuntimeException {
  15. public Integer code;
  16. private String message;
  17. public CommonBizException(Integer code, String message) {
  18. super(message);
  19. this.code = code;
  20. this.message = message;
  21. }
  22. public CommonBizException(Throwable cause) {
  23. super(cause);
  24. this.code = CommonStatus.SERVER_ERROR.getCode();
  25. this.message = cause.getMessage();
  26. }
  27. public CommonBizException(String message) {
  28. super(message);
  29. this.code = CommonStatus.SERVER_ERROR.getCode();
  30. this.message = message;
  31. }
  32. public CommonBizException(IStatus status) {
  33. super(status.getDesc());
  34. this.code = status.getCode();
  35. this.message = status.getDesc();
  36. }
  37. }