From 8389ada5c7e0fa738b78d140a01b24d06a3e8e7c Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Sat, 9 Sep 2023 11:11:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20BaseException?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../commons/exception/BaseException.java | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/main/java/xyz/zhouxy/plusone/commons/exception/BaseException.java b/src/main/java/xyz/zhouxy/plusone/commons/exception/BaseException.java index ae976d8..3b13195 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/exception/BaseException.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/exception/BaseException.java @@ -16,36 +16,43 @@ package xyz.zhouxy.plusone.commons.exception; -import xyz.zhouxy.plusone.commons.base.IWithIntCode; +import xyz.zhouxy.plusone.commons.base.IWithCode; + +import javax.annotation.Nonnull; +import java.util.Objects; /** * 带错误码的异常。 * * @author ZhouXY */ -public abstract class BaseException extends RuntimeException implements IWithIntCode { +public abstract class BaseException + extends RuntimeException + implements IWithCode { private static final long serialVersionUID = -2546365325001947203L; - private final int code; + @Nonnull + private final String code; - protected BaseException(int code, String msg) { + protected BaseException(String code, String msg) { super(msg); - this.code = code; + this.code = Objects.requireNonNull(code); } - protected BaseException(int code, Throwable cause) { + protected BaseException(String code, Throwable cause) { super(cause); - this.code = code; + this.code = Objects.requireNonNull(code); } - protected BaseException(int code, String msg, Throwable cause) { + protected BaseException(String code, String msg, Throwable cause) { super(msg, cause); - this.code = code; + this.code = Objects.requireNonNull(code); } + @Nonnull @Override - public final int getCode() { + public final String getCode() { return this.code; } }