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.
|
public static String getLocalizedMessage(Throwable exception, Locale locale)
Throwable.getLocalizedMessage()
method otherwise. Note that by default,
getLocalizedMessage()
itself fallback on Throwable.getMessage()
.exception
- The exception from which to get the localize message, or null
.locale
- The locale for the message, or null
for the default locale.null
if the exception
argument was null
or the exception does not contain a message.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.Copyright © 2010–2015 The Apache Software Foundation. All rights reserved.