类 Throwables
- java.lang.Object
-
- net.dongliu.commons.Throwables
-
public class Throwables extends java.lang.ObjectUtils method for throwable
-
-
构造器概要
构造器 构造器 说明 Throwables()
-
方法概要
所有方法 静态方法 具体方法 修饰符和类型 方法 说明 static <T extends java.lang.Throwable>
java.util.Optional<T>getCauseOf(java.lang.Throwable throwable, java.lang.Class<T> cls)Get ancestor cause, util the cause is specific type, or throwable has no cause.static java.lang.ThrowablegetRootCause(java.lang.Throwable throwable)Get root cause of throwable.static java.lang.StringgetStackTrace(java.lang.Throwable t)Get stack trace as string.static java.lang.RuntimeExceptionsneakyThrow(java.lang.Throwable t)Throw the throwable without need to add throws clause to method signature.static <T extends java.lang.Throwable>
voidthrowIf(java.lang.Throwable throwable, java.lang.Class<T> cls)If throwable is type T, throw it.static voidthrowIfUnchecked(java.lang.Throwable throwable)If is unchecked (Error, or RuntimeException), throw the throwable
-
-
-
方法详细资料
-
sneakyThrow
public static java.lang.RuntimeException sneakyThrow(java.lang.Throwable t)
Throw the throwable without need to add throws clause to method signature. Usually, it should use like this:throw Throwables.sneakyThrow(e);- 参数:
t- the exception to throw, should not be null
-
throwIfUnchecked
public static void throwIfUnchecked(java.lang.Throwable throwable)
If is unchecked (Error, or RuntimeException), throw the throwable- 参数:
throwable- the throwable
-
throwIf
public static <T extends java.lang.Throwable> void throwIf(java.lang.Throwable throwable, java.lang.Class<T> cls) throws T extends java.lang.ThrowableIf throwable is type T, throw it.- 类型参数:
T- the type- 参数:
throwable- the throwablecls- the type class- 抛出:
T- exceptionT extends java.lang.Throwable
-
getRootCause
public static java.lang.Throwable getRootCause(java.lang.Throwable throwable)
Get root cause of throwable. If throwable do not have a root cause, return its self.- 参数:
throwable- the throwable, cannot be null- 返回:
- the root cause.
-
getCauseOf
public static <T extends java.lang.Throwable> java.util.Optional<T> getCauseOf(java.lang.Throwable throwable, java.lang.Class<T> cls)Get ancestor cause, util the cause is specific type, or throwable has no cause.- 参数:
throwable- the throwable, cannot be null- 返回:
- the cause with specific type, or empty if not such cause.
-
getStackTrace
public static java.lang.String getStackTrace(java.lang.Throwable t)
Get stack trace as string.- 参数:
t- the throwable, cannot be null- 返回:
- the string represent stacktrace of throwable
-
-