| Modifier and Type | Method and Description |
|---|---|
static String |
formatChainedMessages(Locale locale,
String header,
Throwable cause)
Returns a string which contain the given message on the first line, followed by the
localized message of the given exception
on the next line.
|
static String |
getLocalizedMessage(Throwable exception,
Locale locale)
Returns the message of the given exception, localized in the given locale if possible.
|
static <T extends Throwable> |
setMessage(T exception,
String message,
boolean append)
Returns an exception of the same kind and with the same stack trace than the given
exception, but with a different message.
|
static Exception |
unwrap(Exception exception)
If the given exception is a wrapper for another exception, returns the unwrapped exception.
|
public static String getLocalizedMessage(Throwable exception, Locale locale)
exception is null, then this method returns null.locale is null, then this method returns Throwable.getMessage().
This is consistent with the Localized policy saying that null locale stands for "unlocalized"
message (usually in English) or message in the JVM default locale.exception is an instance of LocalizedException providing
a non-null international message,
then this method returns the result of InternationalString.toString(Locale).Throwable.getLocalizedMessage().exception - the exception from which to get the localize message, or null.locale - the preferred locale for the message, or null for the JVM default locale.
This locale is honored on a best-effort basis only.null if the exception
argument was null or if the exception does not contain a message.LocalizedException.getLocalizedMessage()public static <T extends Throwable> T setMessage(T exception, String message, boolean append)
Throwable defined a setMessage(String) method.
We use this method when an external library throws an exception of the right type,
but with too few details.
This method tries to create a new exception using reflection. The exception class needs
to provide a public constructor expecting a single String argument. If the
exception class does not provide such constructor, then the given exception is returned
unchanged.
T - the type of the exception.exception - the exception to copy with a different message.message - the message to set in the exception to be returned.append - if true, the existing message in the original exception (if any)
will be happened after the provided message.Exception(String) constructor.public static String formatChainedMessages(Locale locale, String header, Throwable cause)
SQLException is handled especially in order to process the
next exception instead than the cause.
This method does not format the stack trace.
locale - the preferred locale for the exception message, or null.header - the message to insert on the first line, or null if none.cause - the exception, or null if none.null if both the header was null
and no exception provide a message.public static Exception unwrap(Exception exception)
InvocationTargetException (could be wrapping anything).BackingStoreException (typically wrapping a checked exception).UncheckedIOException (wrapping a IOException).DirectoryIteratorException (wrapping a IOException).SQLException
in other SQLException without additional information.exception - the exception to unwrap (may be null.Copyright © 2010–2017 The Apache Software Foundation. All rights reserved.