IWETHEY v. 0.3.0 | TODO
1,095 registered users | 1 active user | 1 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New I18N (internationalization) and exceptions
I am working on a large project which needs to support I18N. We are having a difficult time with exception messages that are displayed to the user. There seem to be a number of options available (this assumes checked exceptions and every layer wraps). It is assumed that low level exceptions like SQLExceptions do not need to be translated because they are never shown to the user they are just logged.
1. When the business layer catches an exception and wraps it, it should set the message of the new exception based on a resource bundle. The problem with this is that the business llayer then needs to have access to a resource bundle
2. Use the message of the exception as a key into a resource bundle and have the gui layer do the actual translation. The advantage is that only the gui deals with messages that the user sees.
3. Have the exception know how to localize itself (probably by setting some kind of key for a resource bundle). This is the most OO solution.

Any other suggestions/ideas?

New Use exception's class name as a key?
--

...what happened to intelligence of this country?
-- Sen. Kerry.
New That would lead to a lot of exception classes
Basically what you are suggesting is that for every possible error create a new exception class. That is problematic for a number of reasons.
1. You then end up throwing a long list of exceptions making every one catch or throw the long list. The whole point of wrapping exceptions is so that the gui only ends up having to catch a small number of exceptions
2. You end up with a large number of exception classes
Expand Edited by bluke March 9, 2004, 09:31:14 AM EST
New Create a wrapper exception class
call it LocalizedException and provide messageKey and messageParams methods. Use the messageKey to lookup a format string in a resource bundle containing a message format string - then unify that with the messageParams with java.text.MessageFormat.

You can have the exception class do the lookup of the bundle, or leave it to client code. I'd be inclined to put it in the exception itself - implementing something like toString(locale).



The tree of research must from time to time be refreshed with the blood of bean counters.
     -- Alan Kay
     I18N (internationalization) and exceptions - (bluke) - (3)
         Use exception's class name as a key? -NT - (Arkadiy) - (2)
             That would lead to a lot of exception classes - (bluke) - (1)
                 Create a wrapper exception class - (tuberculosis)

Can those of you in the back hear me?
60 ms