public class ExceptionUtil extends Object
| 构造器和说明 |
|---|
ExceptionUtil() |
| 限定符和类型 | 方法和说明 |
|---|---|
static <T extends Throwable> |
convertFromOrSuppressedThrowable(Throwable throwable,
Class<T> exceptionClass)
转化指定异常为来自或者包含指定异常
|
static <T extends Throwable> |
convertFromOrSuppressedThrowable(Throwable throwable,
Class<T> exceptionClass,
boolean checkCause)
转化指定异常为来自或者包含指定异常
|
static Throwable |
getCausedBy(Throwable throwable,
Class<? extends Exception>... causeClasses)
获取由指定异常类引起的异常
|
static String |
getMessage(Throwable e)
获得完整消息,包括异常名
|
static StackTraceElement |
getRootStackElement()
获取入口堆栈信息
|
static String |
getSimpleMessage(Throwable e)
获得消息,调用异常类的getMessage方法
|
static StackTraceElement |
getStackElement(int i)
获取指定层的堆栈信息
|
static StackTraceElement[] |
getStackElements()
获取当前栈信息
|
static boolean |
isCausedBy(Throwable throwable,
Class<? extends Exception>... causeClasses)
判断是否由指定异常类引起
|
static boolean |
isFromOrSuppressedThrowable(Throwable throwable,
Class<? extends Throwable> exceptionClass)
判断指定异常是否来自或者包含指定异常
|
static boolean |
isFromOrSuppressedThrowable(Throwable throwable,
Class<? extends Throwable> exceptionClass,
boolean checkCause)
判断指定异常是否来自或者包含指定异常
|
static String |
stacktraceToOneLineString(Throwable throwable)
堆栈转为单行完整字符串
|
static String |
stacktraceToOneLineString(Throwable throwable,
int limit)
堆栈转为单行完整字符串
|
static String |
stacktraceToString(Throwable throwable)
堆栈转为完整字符串
|
static String |
stacktraceToString(Throwable throwable,
int limit)
堆栈转为完整字符串
|
static String |
stacktraceToString(Throwable throwable,
int limit,
Map<Character,String> replaceCharToStrMap)
堆栈转为完整字符串
|
static Throwable |
unwrap(Throwable wrapped)
剥离反射引发的InvocationTargetException、UndeclaredThrowableException中间异常,返回业务本身的异常
|
static <T extends Throwable> |
wrap(Throwable throwable,
Class<T> wrapThrowable)
包装一个异常
|
static RuntimeException |
wrapRuntime(Throwable throwable)
使用运行时异常包装编译异常
|
public static String getSimpleMessage(Throwable e)
e - 异常public static RuntimeException wrapRuntime(Throwable throwable)
throwable - 异常public static <T extends Throwable> T wrap(Throwable throwable, Class<T> wrapThrowable)
throwable - 异常wrapThrowable - 包装后的异常类public static Throwable unwrap(Throwable wrapped)
wrapped - 包装的异常public static StackTraceElement[] getStackElements()
public static StackTraceElement getStackElement(int i)
public static StackTraceElement getRootStackElement()
public static String stacktraceToOneLineString(Throwable throwable)
throwable - 异常对象public static String stacktraceToOneLineString(Throwable throwable, int limit)
throwable - 异常对象limit - 限制最大长度public static String stacktraceToString(Throwable throwable)
throwable - 异常对象public static String stacktraceToString(Throwable throwable, int limit)
throwable - 异常对象limit - 限制最大长度public static String stacktraceToString(Throwable throwable, int limit, Map<Character,String> replaceCharToStrMap)
throwable - 异常对象limit - 限制最大长度replaceCharToStrMap - 替换字符为指定字符串public static boolean isCausedBy(Throwable throwable, Class<? extends Exception>... causeClasses)
throwable - 异常causeClasses - 定义的引起异常的类public static Throwable getCausedBy(Throwable throwable, Class<? extends Exception>... causeClasses)
throwable - 异常causeClasses - 定义的引起异常的类public static boolean isFromOrSuppressedThrowable(Throwable throwable, Class<? extends Throwable> exceptionClass)
throwable - 异常exceptionClass - 定义的引起异常的类public static boolean isFromOrSuppressedThrowable(Throwable throwable, Class<? extends Throwable> exceptionClass, boolean checkCause)
throwable - 异常exceptionClass - 定义的引起异常的类checkCause - 判断causepublic static <T extends Throwable> T convertFromOrSuppressedThrowable(Throwable throwable, Class<T> exceptionClass)
T - 异常类型throwable - 异常exceptionClass - 定义的引起异常的类Copyright © 2019. All rights reserved.