类 ExceptionUtils
java.lang.Object
cn.taketoday.util.ExceptionUtils
- 作者:
- TODAY
2018-11-13 21:25
-
嵌套类概要
嵌套类 -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明static StringbuildMessage(String message, Throwable cause) Build a message for the given base message and root cause.static ThrowablegetMostSpecificCause(Throwable original) Retrieve the most specific cause of the given exception, that is, either the innermost cause (root cause) or the exception itself.static ThrowablegetRootCause(Throwable original) Retrieve the innermost cause of the given exception, if any.static voidsneakyThrow(ExceptionUtils.Action action) static RuntimeExceptionThrows any throwable 'sneakily' - you don't need to catch it, nor declare that you throw it onwards.static <T> TsneakyThrow(Callable<T> action) static ThrowableUnwrap
-
构造器详细资料
-
ExceptionUtils
public ExceptionUtils()
-
-
方法详细资料
-
unwrapThrowable
Unwrap -
buildMessage
Build a message for the given base message and root cause.- 参数:
message- the base messagecause- the root cause- 返回:
- the full exception message
- 从以下版本开始:
- 3.0
-
getRootCause
Retrieve the innermost cause of the given exception, if any.- 参数:
original- the original exception to introspect- 返回:
- the innermost exception, or
nullif none - 从以下版本开始:
- 3.0
-
getMostSpecificCause
Retrieve the most specific cause of the given exception, that is, either the innermost cause (root cause) or the exception itself.Differs from
getRootCause(java.lang.Throwable)in that it falls back to the original exception if there is no root cause.- 参数:
original- the original exception to introspect- 返回:
- the most specific cause (never
null) - 从以下版本开始:
- 3.0
-
sneakyThrow
Throws any throwable 'sneakily' - you don't need to catch it, nor declare that you throw it onwards. The exception is still thrown - javac will just stop whining about it.Example usage:
public void run() { throw sneakyThrow(new IOException("You don't need to catch me!")); }NB: The exception is not wrapped, ignored, swallowed, or redefined. The JVM actually does not know or care about the concept of a 'checked exception'. All this method does is hide the act of throwing a checked exception from the java compiler.
Note that this method has a return type of
RuntimeException; it is advised you always call this method as argument to thethrowstatement to avoid compiler errors regarding no return statement and similar problems. This method won't of course return an actualRuntimeException- it never returns, it always throws the provided exception.- 参数:
t- The throwable to throw without requiring you to catch its type.- 返回:
- A dummy RuntimeException; this method never returns normally, it always throws an exception!
- 从以下版本开始:
- 4.0
-
sneakyThrow
- 从以下版本开始:
- 4.0
-
sneakyThrow
- 从以下版本开始:
- 4.0
-