Class Exceptions
- java.lang.Object
-
- com.saperion.common.lang.exception.Exceptions
-
public final class Exceptions extends java.lang.Object
The class Exceptions provides exception utility methods.- Author:
- sts
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
formatLocalizedMessagesAsString(java.lang.Throwable throwable, java.util.Locale locale)
Returns aString
containing the localized messages of the specifiedThrowable
and all its causes as returned bygetLocalizedMessages(Throwable, Locale)
separated by a line separator.static java.lang.String
formatStackTraceAsString(java.lang.Throwable throwable, java.util.Locale locale)
Returns aString
containing the full stack trace of the specifiedThrowable
and all its causes.static java.lang.Throwable
getCauseByType(java.lang.Throwable root, java.lang.Class<? extends java.lang.Throwable> causeType)
Returns theroot
cause by the givencauseType
, if existing.static java.lang.String
getLocalizedMessage(java.lang.Throwable throwable, java.util.Locale locale)
Returns the localized message of the specifiedThrowable
.static java.lang.String[]
getLocalizedMessages(java.lang.Throwable throwable, java.util.Locale locale)
Returns an array of the messages of the specifiedThrowable
and all its causes, and tries to get localized messages the same way asgetLocalizedMessage(Throwable, Locale)
would do.static boolean
isCausedBy(java.lang.Throwable root, java.lang.Class<? extends java.lang.Throwable> causeType)
Determines if the givenroot
is caused by the givencauseType
.
-
-
-
Method Detail
-
isCausedBy
public static boolean isCausedBy(java.lang.Throwable root, java.lang.Class<? extends java.lang.Throwable> causeType)
Determines if the givenroot
is caused by the givencauseType
. The whole cause-hierarchy of root is regarded recursively. The specified rootThrowable
must not benull
. The specified causeType must not benull
.- Parameters:
root
- the rootThrowable
to inspect.causeType
- the type of theThrowable
cause in question.- Returns:
- true, if root is caused by the causeType, false otherwise.
-
getCauseByType
public static java.lang.Throwable getCauseByType(java.lang.Throwable root, java.lang.Class<? extends java.lang.Throwable> causeType)
Returns theroot
cause by the givencauseType
, if existing. If a cause matches the givencauseType
is determined by the algorithm:causeType.isInstance(root)
. The whole cause-hierarchy of root is regarded recursively. The first found cause by the givencauseType
is returned. Returnsnull
if no such cause is found. The specified rootThrowable
must not benull
. The specified causeType must not benull
.- Parameters:
root
- the rootThrowable
to inspect.causeType
- the type of theThrowable
cause in question.- Returns:
- the cause by type if existing or
null
if not existing.
-
getLocalizedMessage
public static java.lang.String getLocalizedMessage(java.lang.Throwable throwable, java.util.Locale locale)
Returns the localized message of the specifiedThrowable
. ForBaseException
s it returns the same asBaseException.getLocalizedMessage(Locale)
, for all otherThrowable
s the same asThrowable.getLocalizedMessage()
. The specifiedThrowable
must not benull
. The specifiedLocale
may benull
.- Parameters:
throwable
-Throwable
to get an array of localized messages forlocale
-Locale
to get the localized messages ofBaseException
s for- Returns:
- the localized message
-
getLocalizedMessages
public static java.lang.String[] getLocalizedMessages(java.lang.Throwable throwable, java.util.Locale locale)
Returns an array of the messages of the specifiedThrowable
and all its causes, and tries to get localized messages the same way asgetLocalizedMessage(Throwable, Locale)
would do. The "topmost" message (at index == 0) is the localized message of the specifiedThrowable
. Higher indexes are deeper causes. The specifiedThrowable
must not benull
. The specifiedLocale
may benull
.- Parameters:
throwable
-Throwable
to get the localized message forlocale
-Locale
to get the localized message ofBaseException
s for- Returns:
- array of localized messages
-
formatLocalizedMessagesAsString
public static java.lang.String formatLocalizedMessagesAsString(java.lang.Throwable throwable, java.util.Locale locale)
Returns aString
containing the localized messages of the specifiedThrowable
and all its causes as returned bygetLocalizedMessages(Throwable, Locale)
separated by a line separator. The specifiedThrowable
must not benull
. The specifiedLocale
may benull
.- Parameters:
throwable
-Throwable
to get the localized message forlocale
-Locale
to get the localized message ofBaseException
s for- Returns:
- array of localized messages
-
formatStackTraceAsString
public static java.lang.String formatStackTraceAsString(java.lang.Throwable throwable, java.util.Locale locale)
Returns aString
containing the full stack trace of the specifiedThrowable
and all its causes. ForBaseException
s the content of the returnedString
is the same asThrowable.printStackTrace()
would produce and for all otherThrowable
s it is analogous toThrowable.printStackTrace()
. The specifiedThrowable
must not benull
. The specifiedLocale
may benull
.- Parameters:
throwable
-Throwable
to get the stack trace forlocale
-Locale
to get the localized message ofBaseException
s for- Returns:
String
containing the full stack trace of the specifiedThrowable
and all its causes
-
-