Class Exceptions
- java.lang.Object
-
- com.saperion.common.lang.exception.Exceptions
-
public final class Exceptions extends java.lang.ObjectThe class Exceptions provides exception utility methods.- Author:
- sts
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.StringformatLocalizedMessagesAsString(java.lang.Throwable throwable, java.util.Locale locale)Returns aStringcontaining the localized messages of the specifiedThrowableand all its causes as returned bygetLocalizedMessages(Throwable, Locale)separated by a line separator.static java.lang.StringformatStackTraceAsString(java.lang.Throwable throwable, java.util.Locale locale)Returns aStringcontaining the full stack trace of the specifiedThrowableand all its causes.static java.lang.ThrowablegetCauseByType(java.lang.Throwable root, java.lang.Class<? extends java.lang.Throwable> causeType)Returns therootcause by the givencauseType, if existing.static java.lang.StringgetLocalizedMessage(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 specifiedThrowableand all its causes, and tries to get localized messages the same way asgetLocalizedMessage(Throwable, Locale)would do.static booleanisCausedBy(java.lang.Throwable root, java.lang.Class<? extends java.lang.Throwable> causeType)Determines if the givenrootis 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 givenrootis caused by the givencauseType. The whole cause-hierarchy of root is regarded recursively. The specified rootThrowablemust not benull. The specified causeType must not benull.- Parameters:
root- the rootThrowableto inspect.causeType- the type of theThrowablecause 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 therootcause by the givencauseType, if existing. If a cause matches the givencauseTypeis determined by the algorithm:causeType.isInstance(root). The whole cause-hierarchy of root is regarded recursively. The first found cause by the givencauseTypeis returned. Returnsnullif no such cause is found. The specified rootThrowablemust not benull. The specified causeType must not benull.- Parameters:
root- the rootThrowableto inspect.causeType- the type of theThrowablecause in question.- Returns:
- the cause by type if existing or
nullif not existing.
-
getLocalizedMessage
public static java.lang.String getLocalizedMessage(java.lang.Throwable throwable, java.util.Locale locale)Returns the localized message of the specifiedThrowable. ForBaseExceptions it returns the same asBaseException.getLocalizedMessage(Locale), for all otherThrowables the same asThrowable.getLocalizedMessage(). The specifiedThrowablemust not benull. The specifiedLocalemay benull.- Parameters:
throwable-Throwableto get an array of localized messages forlocale-Localeto get the localized messages ofBaseExceptions 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 specifiedThrowableand 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 specifiedThrowablemust not benull. The specifiedLocalemay benull.- Parameters:
throwable-Throwableto get the localized message forlocale-Localeto get the localized message ofBaseExceptions for- Returns:
- array of localized messages
-
formatLocalizedMessagesAsString
public static java.lang.String formatLocalizedMessagesAsString(java.lang.Throwable throwable, java.util.Locale locale)Returns aStringcontaining the localized messages of the specifiedThrowableand all its causes as returned bygetLocalizedMessages(Throwable, Locale)separated by a line separator. The specifiedThrowablemust not benull. The specifiedLocalemay benull.- Parameters:
throwable-Throwableto get the localized message forlocale-Localeto get the localized message ofBaseExceptions for- Returns:
- array of localized messages
-
formatStackTraceAsString
public static java.lang.String formatStackTraceAsString(java.lang.Throwable throwable, java.util.Locale locale)Returns aStringcontaining the full stack trace of the specifiedThrowableand all its causes. ForBaseExceptions the content of the returnedStringis the same asThrowable.printStackTrace()would produce and for all otherThrowables it is analogous toThrowable.printStackTrace(). The specifiedThrowablemust not benull. The specifiedLocalemay benull.- Parameters:
throwable-Throwableto get the stack trace forlocale-Localeto get the localized message ofBaseExceptions for- Returns:
Stringcontaining the full stack trace of the specifiedThrowableand all its causes
-
-