Package com.alibaba.cloud.ai.util
Class ExceptionUtils
java.lang.Object
com.alibaba.cloud.ai.util.ExceptionUtils
异常处理工具类
- Author:
- zhangshenghang
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ThrowablegetRootCause(Throwable exception) 获取异常的根本原因static StringgetSimpleMessage(Throwable exception) 获取简化的异常消息static voidsafeExecute(Runnable operation, String errorMessage) 安全执行操作,捕获并记录异常static <T> TsafeExecute(Supplier<T> operation, T defaultValue, String errorMessage) 安全执行操作,捕获并记录异常static RuntimeExceptionwrapAsRuntimeException(Exception exception, String message) 包装异常为运行时异常
-
Constructor Details
-
ExceptionUtils
public ExceptionUtils()
-
-
Method Details
-
safeExecute
安全执行操作,捕获并记录异常- Parameters:
operation- 要执行的操作defaultValue- 异常时的默认值errorMessage- 错误消息- Returns:
- 操作结果或默认值
-
safeExecute
安全执行操作,捕获并记录异常- Parameters:
operation- 要执行的操作errorMessage- 错误消息
-
wrapAsRuntimeException
包装异常为运行时异常- Parameters:
exception- 原始异常message- 自定义消息- Returns:
- 运行时异常
-
getRootCause
获取异常的根本原因- Parameters:
exception- 异常- Returns:
- 根本原因
-
getSimpleMessage
获取简化的异常消息- Parameters:
exception- 异常- Returns:
- 简化的异常消息
-