Contents | Prev | Next
Localizing Exceptions
Error messages represent a large category of localizable text in an application. In Java, subclasses of Throwable are used to convey error information from the site of an error, to the error handling code. The initial design of Throwable provided for a message string to be added to the exception when it was created. This design is troublesome because it requires the message to be localized at the error site. Since many errors are caught and never displayed this is inefficient. It is also possible that the default locale at the error site is different than at the presentation site. JDK 1.1 solves these problems by making it possible for exception messages to be localized at the presentation site.
To allow exception messages to be localized at the presentation site, Throwable has the following new constructor:
Throwable( String messageKey, Object[] messageParameters );
The messageKey is a key for a localized message to be retrieved from a ResourceBundle. This key may return a formatted message string or it may return a message pattern as used by the class MessageFormat. If the message is in fact a pattern, then Throwable's Object array contains the arguments to be used in formatting the message. The method getArguments() is used for retrieving the arguments from Throwable.
Contents | Prev | Next
java-intl@java.sun.com
Copyright © 1996 Sun Microsystems, Inc. All rights reserved.