Is there a way to force exception message to be English for Java 1.7

只谈情不闲聊 提交于 2021-01-26 19:29:55

问题


I've almost tried everything including:

  1. Change system region and language to be 'english US'
  2. Use Locale.setDefaultLocale()
  3. Pass in JVM arguments

It prints out:

Default locale is : en_US

BUT my application is still throwing exception with Chinese exception message

Does this have anything to do with Spring? (my app is based on Spring, but there is no locale-related config whatsover, so it should be just using whatever is default)

Can anyone help me with this?

UPDATE:

I'm basically getting a java.io.IOException with Chinese message equivalent to

An existing connection was forcibly closed by the remote host

changing the locale didn't seem to affect this, maybe this is indeed an OS level thing?


回答1:


"An existing connection was forcibly closed by the remote host" is a standard error message from the Windows Sockets library (code 10054).

In retrieving the error message for the error code, the specification of the FormatMessage function says it will take the user or system locale into account. As far as I know, setting the system region and language to English US should do that. Perhaps a Chinese version of Windows just doesn't have English language messages available?




回答2:


Throwable.getLocalizedMessage() might work, assuming that the library you're using provides localized exception messages.



来源:https://stackoverflow.com/questions/17159357/is-there-a-way-to-force-exception-message-to-be-english-for-java-1-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!