Package org.kiwiproject.base
Class KiwiThrowables
- java.lang.Object
-
- org.kiwiproject.base.KiwiThrowables
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classKiwiThrowables.ThrowableInfoImmutable "struct" that contains information from aThrowableinstance.
-
Field Summary
Fields Modifier and Type Field Description static KiwiThrowables.ThrowableInfoEMPTY_THROWABLE_INFO
-
Constructor Summary
Constructors Constructor Description KiwiThrowables()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Optional<String>messageOf(Throwable throwable)Get the message ofThrowablestatic Optional<String>messageOfNullable(Throwable throwable)static Optional<Throwable>nextCauseOf(Throwable throwable)Get the direct cause of theThrowable.static Optional<Throwable>nextCauseOfNullable(Throwable throwable)static Optional<Throwable>rootCauseOf(Throwable throwable)Get the root cause of theThrowable.static Optional<Throwable>rootCauseOfNullable(Throwable throwable)static StringstackTraceOf(Throwable throwable)Simply wraps the Apache Commons'ExceptionUtils.getStackTrace(Throwable)method.static Optional<String>stackTraceOfNullable(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(Throwable throwable)Create aKiwiThrowables.ThrowableInfofrom givenThrowable.static StringtypeOf(Throwable throwable)Get the type ofThrowablestatic Optional<String>typeOfNullable(Throwable throwable)static Throwableunwrap(Throwable throwable, Class<?> wrapperClass)Ifthrowableis of typewrapperClass, then "unwrap" the cause and return it.
-
-
-
Field Detail
-
EMPTY_THROWABLE_INFO
public static final KiwiThrowables.ThrowableInfo EMPTY_THROWABLE_INFO
-
-
Method Detail
-
throwableInfoOfNonNull
public static KiwiThrowables.ThrowableInfo throwableInfoOfNonNull(Throwable throwable)
Create aKiwiThrowables.ThrowableInfofrom givenThrowable.- Parameters:
throwable- aThrowableinstance- Returns:
- a
KiwiThrowables.ThrowableInfoinstance - Throws:
IllegalArgumentException- ifthrowableisnull
-
throwableInfoOfNullable
public static Optional<KiwiThrowables.ThrowableInfo> throwableInfoOfNullable(Throwable throwable)
Create aKiwiThrowables.ThrowableInfofrom givenThrowable.- Parameters:
throwable- aThrowableinstance- Returns:
- a
KiwiThrowables.ThrowableInfoinstance - Throws:
IllegalArgumentException- ifthrowableisnull
-
nextCauseOf
public static Optional<Throwable> nextCauseOf(Throwable throwable)
Get the direct cause of theThrowable.- Parameters:
throwable- theThrowableto analyze- Returns:
- the direct cause
- Throws:
IllegalArgumentException- ifthrowableisnull
-
nextCauseOfNullable
public static Optional<Throwable> nextCauseOfNullable(Throwable throwable)
- Parameters:
throwable- theThrowableto analyze- Returns:
- the direct cause
-
rootCauseOf
public static Optional<Throwable> rootCauseOf(Throwable throwable)
Get the root cause of theThrowable.- Parameters:
throwable- theThrowableto analyze- Returns:
- the root cause
- Throws:
IllegalArgumentException- ifthrowableifnull
-
rootCauseOfNullable
public static Optional<Throwable> rootCauseOfNullable(Throwable throwable)
- Parameters:
throwable- theThrowableto analyze- Returns:
- the root cause
- Throws:
IllegalArgumentException- ifthrowableifnull
-
typeOf
public static String typeOf(Throwable throwable)
Get the type ofThrowable- Parameters:
throwable- theThrowableto analyze- Returns:
- the type
- Throws:
IllegalArgumentException- ifthrowableisnull
-
typeOfNullable
public static Optional<String> typeOfNullable(Throwable throwable)
- Parameters:
throwable- theThrowableto analyze- Returns:
- the type
-
messageOf
public static Optional<String> messageOf(Throwable throwable)
Get the message ofThrowable- Parameters:
throwable- theThrowableto analyze- Returns:
- the message, if present, or
Optional.empty()if not - Throws:
IllegalArgumentException- ifthrowableisnull
-
messageOfNullable
public static Optional<String> messageOfNullable(Throwable throwable)
- Parameters:
throwable- theThrowableto analyze- Returns:
- the message, if present or
Optional.empty()if not
-
stackTraceOf
public static String stackTraceOf(Throwable throwable)
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
public static Optional<String> stackTraceOfNullable(Throwable throwable)
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
-
-