Package com.sodius.oslc.core.util
Class Throwables
- java.lang.Object
-
- com.sodius.oslc.core.util.Throwables
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Iterator<Throwable>
getCauseChain(Throwable throwable)
Gets aThrowable
cause chain as an iterator.static Optional<Throwable>
getCauseInChain(Throwable throwable, Class<?>... types)
Returns the most immediate cause in the chain of one of the given types (or sub types).static <T extends Throwable>
Optional<T>getCauseInChain(Throwable throwable, Class<T> type)
Returns the most immediate cause in the chain of the given type (or sub type).static Throwable
getRootCause(Throwable throwable)
Returns the innermost cause ofthrowable
, orthrowable
itself if it has no cause.
-
-
-
Method Detail
-
getCauseChain
public static Iterator<Throwable> getCauseChain(Throwable throwable)
Gets aThrowable
cause chain as an iterator. The first entry in the iterator will bethrowable
followed by its cause hierarchy.- Parameters:
throwable
- the throwable whose cause chain is to determine- Returns:
- an iterator to navigate in the cause chain
-
getRootCause
public static Throwable getRootCause(Throwable throwable)
Returns the innermost cause ofthrowable
, orthrowable
itself if it has no cause.- Parameters:
throwable
- the throwable whose root cause is to determine- Returns:
- the innermost cause
-
getCauseInChain
public static Optional<Throwable> getCauseInChain(Throwable throwable, Class<?>... types)
Returns the most immediate cause in the chain of one of the given types (or sub types).- Parameters:
throwable
- the throwable whose cause is to determinetypes
- the types of cause to look for- Returns:
- the most immediate cause in the chain of one of the given types (or sub types), empty if none
-
getCauseInChain
public static <T extends Throwable> Optional<T> getCauseInChain(Throwable throwable, Class<T> type)
Returns the most immediate cause in the chain of the given type (or sub type).- Type Parameters:
T
- the type of cause to look for- Parameters:
throwable
- the throwable whose cause is to determinetype
- the type of cause to look for- Returns:
- the most immediate cause in the chain of the given type (or sub type), empty if none
-
-