- java.lang.Object
-
- de.carne.util.Exceptions
-
public final class Exceptions extends java.lang.ObjectUtility class providing Exception/Throwable handling related functions.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.ThrowablegetCause(java.lang.Throwable exception)Checks and gets the submitted Throwable's causing exception.static java.lang.StringgetMessage(@Nullable java.lang.Throwable exception)Gets an Throwable's best message.static java.lang.StringgetStackTrace(java.lang.Throwable exception)Gets a Throwable's stack trace.static voidignore(@Nullable java.lang.Throwable exception)Ignores a Throwable.static java.lang.RuntimeExceptiontoRuntime(java.lang.Throwable exception)Makes a Throwable unchecked by wrapping it into a RuntimeException if needed.static java.lang.StringtoString(java.lang.Throwable e)Determines the best textual representation of a Throwable.static voidwarn(@Nullable java.lang.Throwable exception)Warns about a Throwable.
-
-
-
Method Detail
-
toRuntime
public static java.lang.RuntimeException toRuntime(java.lang.Throwable exception)
Makes a Throwable unchecked by wrapping it into a RuntimeException if needed.- Parameters:
exception- the Throwable to wrap.- Returns:
- the created RuntimeException.
-
ignore
public static void ignore(@Nullable java.lang.Throwable exception)
Ignores a Throwable.This function logs the Throwable using the trace log level and discards it.
- Parameters:
exception- the Throwable to ignore (may benull).
-
warn
public static void warn(@Nullable java.lang.Throwable exception)
Warns about a Throwable.This function logs the Throwable using the warning log level and discards it.
- Parameters:
exception- the Throwable to warn about (may benull).
-
getMessage
public static java.lang.String getMessage(@Nullable java.lang.Throwable exception)
Gets an Throwable's best message.This function returns a default message in case
nullis submitted. Otherwise it tries Throwable.getLocalizedMessage() and Throwable.getMessage() to get the best possible message. The former function do not return anything the Throwable's type is returned.- Parameters:
exception- the Throwable to get the message from.- Returns:
- the Throwable's message.
-
getCause
public static java.lang.Throwable getCause(java.lang.Throwable exception)
Checks and gets the submitted Throwable's causing exception.- Parameters:
exception- the Throwable to get the causing exception for.- Returns:
- the causing exception of the submitted exception itself if no cause is set.
-
getStackTrace
public static java.lang.String getStackTrace(java.lang.Throwable exception)
Gets a Throwable's stack trace.- Parameters:
exception- the Throwable to get the stack trace for.- Returns:
- the Throwable's stack trace.
-
toString
public static java.lang.String toString(java.lang.Throwable e)
Determines the best textual representation of a Throwable.- Parameters:
e- The Throwable to get the textual representation for.- Returns:
- The Throwable's message or it's type (if no message is available).
-
-