Chris is right. But what if you want to also localize the Exception string. For example, you throw an exception, and when you catch it, you want to display an exception message to the user. I would like to put them in strings.xml, but at the same time I do not want to use this code
throw new Exception(context.getString(R.string.my_exception_message))
because I think that if you have an exception, you probably donβt want to, and you cannot use additional code to receive the exception message.
I think the only solution would be to declare a static String for this message in your main Office and initialize it as soon as possible (for example, in the onCreate () method):
private static String my_exception_message; public onCreate() { my_exception_message = context.getString(R.string.my_exception_message); }
Therefore, when you throw an exception, you have a localized message ready to use it. What do you think? Can you think of some other solutions?
PinoSan Mar 30 '11 at 11:05 2011-03-30 11:05
source share