Package com.elitesland.ystdms.sys.util
Class ExceptionUtil
java.lang.Object
com.elitesland.ystdms.sys.util.ExceptionUtil
异常处理工具类
提供统一的异常处理方法和异常创建方法
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface函数式接口,允许在lambda表达式中抛出受检异常 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringlogAndGetMessage(Exception e, String message) 记录异常并返回异常信息static voidlogAndThrowBusinessException(Exception e, String message) 记录异常并抛出业务异常static void检查条件,如果不满足则抛出异常static voidrequireNonNull(Object object, String message) 检查对象是否非空,如果为空则抛出异常static voidrequireNonNullAsNotFound(Object object, String message) 检查对象是否非空,如果为空则抛出资源未找到异常static voidsafeExecute(Runnable operation, ExceptionUtil.ConsumerWithException<Exception> onError) 安全执行可能抛出异常的操作static voidthrowBusinessException(ApiCode apiCode, String message) 抛出业务异常static voidthrowBusinessException(Integer code, String message) 抛出业务异常static voidthrowBusinessException(String message) 抛出业务异常static voidthrowResourceNotFoundException(String message) 抛出资源未找到异常static voidthrowUnauthorizedException(String message) 抛出未授权异常static voidthrowValidationException(String message) 抛出验证异常
-
Constructor Details
-
ExceptionUtil
public ExceptionUtil()
-
-
Method Details
-
throwBusinessException
抛出业务异常- Parameters:
message- 异常消息
-
throwBusinessException
抛出业务异常- Parameters:
apiCode- 异常码message- 异常消息
-
throwBusinessException
抛出业务异常- Parameters:
code- 自定义错误码message- 异常消息
-
throwValidationException
抛出验证异常- Parameters:
message- 异常消息
-
throwResourceNotFoundException
抛出资源未找到异常- Parameters:
message- 异常消息
-
throwUnauthorizedException
抛出未授权异常- Parameters:
message- 异常消息
-
logAndGetMessage
记录异常并返回异常信息- Parameters:
e- 异常message- 额外消息- Returns:
- 异常消息
-
logAndThrowBusinessException
记录异常并抛出业务异常- Parameters:
e- 异常message- 额外消息
-
safeExecute
public static void safeExecute(Runnable operation, ExceptionUtil.ConsumerWithException<Exception> onError) 安全执行可能抛出异常的操作- Parameters:
operation- 要执行的操作onError- 发生错误时的回调
-
require
检查条件,如果不满足则抛出异常- Parameters:
condition- 条件message- 异常消息
-
requireNonNull
检查对象是否非空,如果为空则抛出异常- Parameters:
object- 对象message- 异常消息
-
requireNonNullAsNotFound
检查对象是否非空,如果为空则抛出资源未找到异常- Parameters:
object- 对象message- 异常消息
-