BusinessException.java 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package com.pj.project4sp.global;
  2. import com.pj.constants.ErrorMsgEnum;
  3. import lombok.Data;
  4. /**
  5. * @author qzy
  6. * @description 业务异常
  7. * @date Create in 2021/4/22
  8. */
  9. @Data
  10. public class BusinessException extends RuntimeException {
  11. private static final long serialVersionUID = -8661950806210020649L;
  12. private Integer code;
  13. /**
  14. * 验证的时候,手动抛该异常
  15. *
  16. * @param errMsg 定义的错误信息
  17. */
  18. public BusinessException(String errMsg) {
  19. super(errMsg);
  20. this.code=500;
  21. }
  22. /**
  23. * 验证的时候,手动抛该异常
  24. *
  25. * @param errMsg 定义的错误信息
  26. */
  27. public BusinessException(String errMsg, Integer code) {
  28. super(errMsg);
  29. this.code=code;
  30. }
  31. public BusinessException(ErrorMsgEnum errMsg) {
  32. super(errMsg.getMsg());
  33. this.code=errMsg.getCode();
  34. }
  35. /**
  36. * catch中抛该异常
  37. *
  38. * @param errMsg 自定义的错误信息
  39. * @param e 异常
  40. */
  41. public BusinessException(String errMsg, Throwable e) {
  42. super(errMsg, e);
  43. }
  44. }