Class ExceptionUtils

java.lang.Object
com.alibaba.cloud.ai.util.ExceptionUtils

public class ExceptionUtils extends Object
异常处理工具类
Author:
zhangshenghang
  • Constructor Details

    • ExceptionUtils

      public ExceptionUtils()
  • Method Details

    • safeExecute

      public static <T> T safeExecute(Supplier<T> operation, T defaultValue, String errorMessage)
      安全执行操作,捕获并记录异常
      Parameters:
      operation - 要执行的操作
      defaultValue - 异常时的默认值
      errorMessage - 错误消息
      Returns:
      操作结果或默认值
    • safeExecute

      public static void safeExecute(Runnable operation, String errorMessage)
      安全执行操作,捕获并记录异常
      Parameters:
      operation - 要执行的操作
      errorMessage - 错误消息
    • wrapAsRuntimeException

      public static RuntimeException wrapAsRuntimeException(Exception exception, String message)
      包装异常为运行时异常
      Parameters:
      exception - 原始异常
      message - 自定义消息
      Returns:
      运行时异常
    • getRootCause

      public static Throwable getRootCause(Throwable exception)
      获取异常的根本原因
      Parameters:
      exception - 异常
      Returns:
      根本原因
    • getSimpleMessage

      public static String getSimpleMessage(Throwable exception)
      获取简化的异常消息
      Parameters:
      exception - 异常
      Returns:
      简化的异常消息