public class ExceptionUtil extends Object
CloneableException| Constructor and Description |
|---|
ExceptionUtil() |
| Modifier and Type | Method and Description |
|---|---|
static <T extends Throwable> |
clearStackTrace(T throwable)
清除StackTrace.
|
static <T extends Throwable> |
findCause(Throwable throwable,
Class<T> cause)
获取某种类型的cause,如果没有则返回空
copy from Jodd ExceptionUtil
|
static Throwable |
getRootCause(Throwable t)
获取异常的Root Cause.
|
static boolean |
isCausedBy(Throwable throwable,
Class<? extends Exception>... causeExceptionClasses)
判断异常是否由某些底层的异常引起.
|
static <T extends Throwable> |
setStackTrace(T throwable,
Class<?> throwClass,
String throwClazz)
copy from Netty, 为静态异常设置StackTrace.
|
static String |
stackTraceText(Throwable t)
将StackTrace[]转换为String, 供Logger或e.printStackTrace()外的其他地方使用.
|
static String |
toStringWithRootCause(Throwable t)
拼装 短异常类名: 异常信息 <-- RootCause的短异常类名: 异常信息
|
static String |
toStringWithShortName(Throwable t)
拼装 短异常类名: 异常信息.
|
static RuntimeException |
unchecked(Throwable t)
将CheckedException转换为RuntimeException重新抛出, 可以减少函数签名中的CheckExcetpion定义.
|
static Throwable |
unwrap(Throwable t)
如果是著名的包裹类,从cause中获得真正异常.
|
static RuntimeException |
unwrapAndUnchecked(Throwable t)
组合unwrap与unchecked,用于处理反射/Callable的异常
|
public static RuntimeException unchecked(Throwable t)
try{ ... }catch(Exception e){ throw unchecked(t); }
ExceptionUtils.wrapAndThrow(Throwable)public static Throwable unwrap(Throwable t)
public static RuntimeException unwrapAndUnchecked(Throwable t)
public static String stackTraceText(Throwable t)
public static String toStringWithShortName(Throwable t)
ExceptionUtils.getMessage(Throwable)public static String toStringWithRootCause(Throwable t)
public static Throwable getRootCause(Throwable t)
Throwables.getRootCause(Throwable)public static <T extends Throwable> T findCause(Throwable throwable, Class<T> cause)
public static boolean isCausedBy(Throwable throwable, Class<? extends Exception>... causeExceptionClasses)
public static <T extends Throwable> T setStackTrace(T throwable, Class<?> throwClass, String throwClazz)
private static RuntimeException TIMEOUT_EXCEPTION = ExceptionUtil.setStackTrace(new RuntimeException("Timeout"),
MyClass.class, "mymethod");
public static <T extends Throwable> T clearStackTrace(T throwable)
Copyright © 2018. All rights reserved.