Difference between getmessage and getlocalizedmessage in exceptions Java?

Difference between getmessage and getlocalizedmessage in exceptions Java?

  • Difference between getmessage and getlocalizedmessage in exceptions Java?_第1张图片
View Slide Show
Answer:

Java Exceptions inherit their getMessage and getLocalizedMessage methods from Throwable (see the related link). The difference is that subclasses should override getLocalizedMessage to provide a locale-specific message.

For example, imaging that you're adapting code from an American-English speaking company/group to a British-English group. You may want to create custom Exception classes which override the getLocalizedMessage to correct spelling and grammer to what the users and developers who will be using your code might expect. This can also be used for actual translations of Exception messages.

你可能感兴趣的:(Java,J2SE)