Class InternationalizedException
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
PackageCreatorException
InternationalizedException
class adds internationalization support to the
standard functionality provided by java.lang.Exception
.
To support internationalization, the thrower of an exception must not specify a hardcoded message
string. Instead, the thrower specifies a key that identifies the message. That key is then looked
up in a locale-specific ResourceBundle
to find the actual
message associated with this exception.
This class also supports arguments to messages. The full message will be constructed using the
MessageFormat
class. For more information on
internationalization, see the
Java Internationalization Guide.
This version of this class works with JDK versions prior to 1.4, since it does not assume support
for exception chaining. The file InternationalizedException.java_1_4
is a version
that uses the exception chaining support built-in to JDK1.4.
- See Also:
-
Constructor Summary
ConstructorDescriptionCreates a newInternationalizedException
with a null message.InternationalizedException
(String aResourceBundleName, String aMessageKey, Object[] aArguments) Creates a newInternationalizedException
with the specified message.InternationalizedException
(String aResourceBundleName, String aMessageKey, Object[] aArguments, Throwable aCause) Creates a newInternationalizedException
with the specified message and cause.InternationalizedException
(Throwable aCause) Creates a newInternationalizedException
with the specified cause and a null message. -
Method Summary
Modifier and TypeMethodDescriptionObject[]
Gets the arguments to this exception's message.getCause()
Gets the cause of this Exception.Gets the localized detail message for this exception.getLocalizedMessage
(Locale aLocale) Gets the localized detail message for this exception using the specifiedLocale
.Gets the English detail message for this exception.Gets the identifier for this exception's message.Gets the base name of the resource bundle in which the message for this exception is located.boolean
hasMessageKey
(String messageKey) Checks if this exception, or any of its root causes, has a particular UIMA message key.void
setResourceBundle
(Locale aLocale) For the case where the default locale is not being used for getting messages, and the lookup path in the classpath for the resource bundle needs to be set at a specific point, call this method to set the resource bundle at that point in the call stack.Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getStackTrace, getSuppressed, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Constructor Details
-
InternationalizedException
public InternationalizedException()Creates a newInternationalizedException
with a null message. -
InternationalizedException
Creates a newInternationalizedException
with the specified cause and a null message.- Parameters:
aCause
- the original exception that caused this exception to be thrown, if any
-
InternationalizedException
public InternationalizedException(String aResourceBundleName, String aMessageKey, Object[] aArguments) Creates a newInternationalizedException
with the specified message.- Parameters:
aResourceBundleName
- the base name of the resource bundle in which the message for this exception is located.aMessageKey
- an identifier that maps to the message for this exception. The message may contain placeholders for arguments as defined by theMessageFormat
class.aArguments
- The arguments to the message.null
may be used if the message has no arguments.
-
InternationalizedException
public InternationalizedException(String aResourceBundleName, String aMessageKey, Object[] aArguments, Throwable aCause) Creates a newInternationalizedException
with the specified message and cause.- Parameters:
aResourceBundleName
- the base name of the resource bundle in which the message for this exception is located.aMessageKey
- an identifier that maps to the message for this exception. The message may contain placeholders for arguments as defined by theMessageFormat
class.aArguments
- The arguments to the message.null
may be used if the message has no arguments.aCause
- the original exception that caused this exception to be thrown, if any
-
-
Method Details
-
getResourceBundleName
Gets the base name of the resource bundle in which the message for this exception is located.- Returns:
- the resource bundle base name. May return
null
if this exception has no message.
-
getMessageKey
Gets the identifier for this exception's message. This identifier can be looked up in this exception'sResourceBundle
to get the locale-specific message for this exception.- Returns:
- the resource identifier for this exception's message. May return
null
if this exception has no message.
-
getArguments
Gets the arguments to this exception's message. Arguments allow aInternationalizedException
to have a compound message, made up of multiple parts that are concatenated in a language-neutral way.- Returns:
- the arguments to this exception's message.
-
getMessage
Gets the English detail message for this exception. For the localized message usegetLocalizedMessage()
.- Overrides:
getMessage
in classThrowable
- Returns:
- the English detail message for this exception.
-
getLocalizedMessage
Gets the localized detail message for this exception. This uses the default Locale for this JVM. A Locale may be specified usinggetLocalizedMessage(Locale)
.- Overrides:
getLocalizedMessage
in classThrowable
- Returns:
- this exception's detail message, localized for the default Locale.
-
getLocalizedMessage
Gets the localized detail message for this exception using the specifiedLocale
.- Parameters:
aLocale
- the locale to use for localizing the message- Returns:
- this exception's detail message, localized for the specified
Locale
.
-
getCause
Gets the cause of this Exception. -
hasMessageKey
Checks if this exception, or any of its root causes, has a particular UIMA message key. This allows checking for particular error condition- Parameters:
messageKey
- to search for in the exception chain- Returns:
- true if this exception or any of its root causes has a particular UIMA message key.
-
initCause
-
setResourceBundle
For the case where the default locale is not being used for getting messages, and the lookup path in the classpath for the resource bundle needs to be set at a specific point, call this method to set the resource bundle at that point in the call stack. Example: If in a Pear, and you are throwing an exception, which is defined in a bundle in the Pear context, but the catcher of the throw is up the stack above where the pear context exists (and therefore, is no longer present at "catch" time), and you don't want to use the default-locale for getting the message out of the message bundle, then do something like this:Exception e = new AnalysisEngineProcessException(MESSAGE_BUNDLE, "TEST_KEY", objects); e.setResourceBundle(my_locale); // call this method, pass in the needed locale object throw e; // or whatever should be done with it
- Parameters:
aLocale
- the locale to use when getting the message from the message bundle at a later time
-