Previous | Next | Trail Map | Internationalization | Contents

Working with Exceptions

In the lesson, Handling Errors with Exceptions, we showed you how to throw and catch exceptions. As you may recall, the exception messages displayed by the examples of that lesson are in U.S. English. Often, exception messages are used only for debugging purposes and are never seen by end-users. However, if the end-users of your program are exposed to exception messages, then you should make sure that the messages are not hardcoded in any one language.

In this section, we'll give you some tips on making exception messages locale-independent. The coding examples in this section include ResourceBundle and MessageFormat objects. If you haven't already done so, before proceeding you may want to read, Isolating Locale-specific Objects in a ResourceBundle, and Message Formatting.

Handling Hardcoded Exception Messages

If the message text of an Exception subclass has been hardcoded, it cannot be localized. But there is a workaround, which we explain in this section.

Creating Locale-independent Exception Subclasses

If you are creating an Exception subclass, you should make sure it doesn't contain a hardcoded message. In your subclass, you should implement the getLocalizedMessage method.


Previous | Next | Trail Map | Internationalization | Contents