在ValidateException新增matchThrow和nonMatchThrow

This commit is contained in:
VampireAchao 2022-02-08 22:26:28 +08:00 committed by achao
parent 238898e708
commit 32ad8ad824

View File

@ -44,4 +44,29 @@ public class ValidateException extends StatefulException {
public ValidateException(int status, String msg, Throwable throwable) { public ValidateException(int status, String msg, Throwable throwable) {
super(status, msg, throwable); super(status, msg, throwable);
} }
/**
* 满足条件就抛出异常
*
* @param condition 条件
* @param msg 异常消息
*/
public static void matchThrow(boolean condition, String msg) {
if (condition) {
throw new ValidateException(msg);
}
}
/**
* 不满足条件就抛出异常
*
* @param condition 条件
* @param msg 异常消息
*/
public static void nonMatchThrow(boolean condition, String msg) {
if (false == condition) {
throw new ValidateException(msg);
}
}
} }