柯桥增值式服务
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

79 lignes
2.0KB

  1. package com.ningdatech.kqapi.common.exception;
  2. import com.ningdatech.kqapi.common.exception.code.BaseExceptionCode;
  3. /**
  4. * 业务异常
  5. * 用于在处理业务逻辑时,进行抛出的异常。
  6. *
  7. * @author WendyYang
  8. * @version 1.0
  9. */
  10. public class BizException extends BaseUncheckedException {
  11. private static final long serialVersionUID = -3843907364558373817L;
  12. public BizException(Throwable cause) {
  13. super(cause);
  14. }
  15. public BizException(int code, Throwable cause) {
  16. super(code, cause);
  17. }
  18. public BizException(String message) {
  19. super(-1, message);
  20. }
  21. public BizException(String message, Throwable cause) {
  22. super(-1, message, cause);
  23. }
  24. public BizException(int code, String message) {
  25. super(code, message);
  26. }
  27. public BizException(int code, String message, Throwable cause) {
  28. super(code, message, cause);
  29. }
  30. public BizException(int code, String message, Object... args) {
  31. super(code, message, args);
  32. }
  33. /**
  34. * 实例化异常
  35. *
  36. * @param code 自定义异常编码
  37. * @param message 自定义异常消息
  38. * @param args 已定义异常参数
  39. * @return 异常实例
  40. */
  41. public static BizException wrap(int code, String message, Object... args) {
  42. return new BizException(code, message, args);
  43. }
  44. public static BizException wrap(String message, Object... args) {
  45. return new BizException(-1, message, args);
  46. }
  47. public static BizException validFail(String message, Object... args) {
  48. return new BizException(-9, message, args);
  49. }
  50. public static BizException wrap(BaseExceptionCode ex) {
  51. return new BizException(ex.getCode(), ex.getMsg());
  52. }
  53. public static BizException wrap(BaseExceptionCode ex, Throwable cause) {
  54. return new BizException(ex.getCode(), ex.getMsg(), cause);
  55. }
  56. @Override
  57. public String toString() {
  58. return "BizException [message=" + getMessage() + ", code=" + getCode() + "]";
  59. }
  60. }