Package org.miaixz.bus.core.xyz
Class ExceptionKit
java.lang.Object
org.miaixz.bus.core.xyz.ExceptionKit
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends Throwable>
TconvertFromOrSuppressedThrowable(Throwable throwable, Class<T> exceptionClass) 转化指定异常为来自或者包含指定异常static <T extends Throwable>
TconvertFromOrSuppressedThrowable(Throwable throwable, Class<T> exceptionClass, boolean checkCause) 转化指定异常为来自或者包含指定异常static ThrowablegetCausedBy(Throwable throwable, Class<? extends Exception>... causeClasses) 获取由指定异常类引起的异常static String获得完整消息,包括异常名,消息格式为:{SimpleClassName}: {ThrowableMessage}static ThrowablegetRootCause(Throwable throwable) 获取异常链中最尾端的异常,即异常最早发生的异常对象。static String获取异常链中最尾端的异常的消息,消息格式为:{SimpleClassName}: {ThrowableMessage}static StackTraceElement获取入口堆栈信息static String获得消息,调用异常类的getMessage方法static StackTraceElementgetStackElement(int i) 获取指定层的堆栈信息static StackTraceElementgetStackElement(String fqcn, int i) 获取指定层的堆栈信息static StackTraceElement[]获取当前栈信息getThrowableList(Throwable throwable) 获取异常链上所有异常的集合,如果Throwable对象没有cause,返回只有一个节点的List 如果传入null,返回空集合static booleanisCausedBy(Throwable throwable, Class<? extends Exception>... causeClasses) 判断是否由指定异常类引起static booleanisFromOrSuppressedThrowable(Throwable throwable, Class<? extends Throwable> exceptionClass) 判断指定异常是否来自或者包含指定异常static booleanisFromOrSuppressedThrowable(Throwable throwable, Class<? extends Throwable> exceptionClass, boolean checkCause) 判断指定异常是否来自或者包含指定异常static StringstacktraceToOneLineString(Throwable throwable) 堆栈转为单行完整字符串static StringstacktraceToOneLineString(Throwable throwable, int limit) 堆栈转为单行完整字符串static StringstacktraceToString(Throwable throwable) 堆栈转为完整字符串static StringstacktraceToString(Throwable throwable, int limit) 堆栈转为完整字符串static StringstacktraceToString(Throwable throwable, int limit, Map<Character, String> replaceCharToStrMap) 堆栈转为完整字符串static Throwable剥离反射引发的InvocationTargetException、UndeclaredThrowableException中间异常,返回业务本身的异常static <T extends Throwable>
T包装一个异常static voidwrapAndThrow(Throwable throwable) static RuntimeExceptionwrapRuntime(String message) 将指定的消息包装为运行时异常static RuntimeExceptionwrapRuntime(Throwable throwable) 使用运行时异常包装编译异常 如果传入参数已经是运行时异常,则直接返回,不再额外包装static voidwrapRuntimeAndThrow(String message) 将消息包装为运行时异常并抛出
-
Constructor Details
-
ExceptionKit
public ExceptionKit()
-
-
Method Details
-
getMessage
-
getSimpleMessage
-
wrapRuntime
使用运行时异常包装编译异常 如果传入参数已经是运行时异常,则直接返回,不再额外包装- Parameters:
throwable- 异常- Returns:
- 运行时异常
-
wrapRuntime
将指定的消息包装为运行时异常- Parameters:
message- 异常消息- Returns:
- 运行时异常
-
wrap
-
wrapAndThrow
- Parameters:
throwable- 异常
-
wrapRuntimeAndThrow
-
unwrap
-
getStackElements
-
getStackElement
获取指定层的堆栈信息- Parameters:
i- 层数- Returns:
- 指定层的堆栈信息
-
getStackElement
获取指定层的堆栈信息- Parameters:
fqcn- 指定类名为基础i- 指定类名的类堆栈相对层数- Returns:
- 指定层的堆栈信息
-
getRootStackElement
-
stacktraceToOneLineString
-
stacktraceToOneLineString
-
stacktraceToString
-
stacktraceToString
-
stacktraceToString
-
isCausedBy
-
getCausedBy
-
isFromOrSuppressedThrowable
-
isFromOrSuppressedThrowable
-
convertFromOrSuppressedThrowable
-
convertFromOrSuppressedThrowable
-
getThrowableList
-
getRootCause
获取异常链中最尾端的异常,即异常最早发生的异常对象。 此方法通过调用Throwable.getCause()直到没有cause为止,如果异常本身没有cause,返回异常本身 传入null返回也为null- Parameters:
throwable- 异常对象,可能为null- Returns:
- 最尾端异常,传入null参数返回也为null
-
getRootCauseMessage
-