Class Exceptions
java.lang.Object
com.saperion.common.lang.exception.Exceptions
The class Exceptions provides exception utility methods.
- Author:
- sts
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
formatLocalizedMessagesAsString
(Throwable throwable, 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 String
formatStackTraceAsString
(Throwable throwable, Locale locale) static Throwable
getCauseByType
(Throwable root, Class<? extends Throwable> causeType) Returns theroot
cause by the givencauseType
, if existing.static String
getLocalizedMessage
(Throwable throwable, Locale locale) Returns the localized message of the specifiedThrowable
.static String[]
getLocalizedMessages
(Throwable throwable, 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
(Throwable root, Class<? extends Throwable> causeType) Determines if the givenroot
is caused by the givencauseType
.
-
Method Details
-
isCausedBy
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
. -
getCauseByType
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
. -
getLocalizedMessage
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
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
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
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
-