Package org.kiwiproject.base
Class KiwiThrowables
java.lang.Object
org.kiwiproject.base.KiwiThrowables
Utility class for working with
Throwable instances.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classImmutable "struct" that contains information from aThrowableinstance. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final KiwiThrowables.ThrowableInfoRepresents an "empty"KiwiThrowables.ThrowableInfo, which is when the Throwable it comes from is null. -
Method Summary
Modifier and TypeMethodDescriptionstatic KiwiThrowables.ThrowableInfoGet the singleton "empty" instance.Get the message ofThrowablemessageOfNullable(@Nullable Throwable throwable) nextCauseOf(Throwable throwable) Get the direct cause of theThrowable.nextCauseOfNullable(@Nullable Throwable throwable) rootCauseOf(Throwable throwable) Get the root cause of theThrowable.rootCauseOfNullable(@Nullable Throwable throwable) static StringstackTraceOf(Throwable throwable) Simply wraps the Apache Commons'ExceptionUtils.getStackTrace(Throwable)method.stackTraceOfNullable(@Nullable Throwable throwable) Simply wraps the Apache Commons'ExceptionUtils.getStackTrace(Throwable)method.static KiwiThrowables.ThrowableInfothrowableInfoOfNonNull(Throwable throwable) Create aKiwiThrowables.ThrowableInfofrom givenThrowable.static Optional<KiwiThrowables.ThrowableInfo>throwableInfoOfNullable(@Nullable Throwable throwable) Create aKiwiThrowables.ThrowableInfofrom givenThrowable.static StringGet the type ofThrowabletypeOfNullable(@Nullable Throwable throwable) static ThrowableIfthrowableis of typewrapperClass, then "unwrap" the cause and return it.
-
Field Details
-
EMPTY_THROWABLE_INFO
Represents an "empty"KiwiThrowables.ThrowableInfo, which is when the Throwable it comes from is null.
-
-
Method Details
-
emptyThrowableInfo
Get the singleton "empty" instance.- Returns:
- the "empty" ThrowableInfo singleton instance
- See Also:
-
throwableInfoOfNonNull
Create aKiwiThrowables.ThrowableInfofrom givenThrowable.- Parameters:
throwable- aThrowableinstance- Returns:
- a
KiwiThrowables.ThrowableInfoinstance - Throws:
IllegalArgumentException- ifthrowableisnull
-
throwableInfoOfNullable
public static Optional<KiwiThrowables.ThrowableInfo> throwableInfoOfNullable(@Nullable Throwable throwable) Create aKiwiThrowables.ThrowableInfofrom givenThrowable.- Parameters:
throwable- aThrowableinstance- Returns:
- a
KiwiThrowables.ThrowableInfoinstance - Throws:
IllegalArgumentException- ifthrowableisnull
-
nextCauseOf
Get the direct cause of theThrowable.- Parameters:
throwable- theThrowableto analyze- Returns:
- the direct cause
- Throws:
IllegalArgumentException- ifthrowableisnull
-
nextCauseOfNullable
- Parameters:
throwable- theThrowableto analyze- Returns:
- the direct cause
-
rootCauseOf
Get the root cause of theThrowable.- Parameters:
throwable- theThrowableto analyze- Returns:
- the root cause
- Throws:
IllegalArgumentException- ifthrowableifnull
-
rootCauseOfNullable
- Parameters:
throwable- theThrowableto analyze- Returns:
- the root cause
- Throws:
IllegalArgumentException- ifthrowableifnull
-
typeOf
Get the type ofThrowable- Parameters:
throwable- theThrowableto analyze- Returns:
- the type
- Throws:
IllegalArgumentException- ifthrowableisnull
-
typeOfNullable
- Parameters:
throwable- theThrowableto analyze- Returns:
- the type
-
messageOf
Get the message ofThrowable- Parameters:
throwable- theThrowableto analyze- Returns:
- the message, if present, or
Optional.empty()if not - Throws:
IllegalArgumentException- ifthrowableisnull
-
messageOfNullable
- Parameters:
throwable- theThrowableto analyze- Returns:
- the message, if present or
Optional.empty()if not
-
stackTraceOf
Simply wraps the Apache Commons'ExceptionUtils.getStackTrace(Throwable)method. Mainly here to make it easy to obtain a stack trace while staying in the sameKiwiThrowablesAPI.- Parameters:
throwable- theThrowableinstance- Returns:
- the stack trace of the
throwable, ornull - Throws:
IllegalArgumentException- ifthrowableisnull
-
stackTraceOfNullable
Simply wraps the Apache Commons'ExceptionUtils.getStackTrace(Throwable)method. Mainly here to make it easy to obtain a stack trace while staying in the sameKiwiThrowablesAPI.- Parameters:
throwable- theThrowableinstance- Returns:
- the stack trace of the
throwable, ornull - Throws:
IllegalArgumentException- ifthrowableisnull
-
unwrap
Ifthrowableis of typewrapperClass, then "unwrap" the cause and return it. Otherwise returnthrowable
-