Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 875
littlejedi Avatar asked Jun 18 '13 01:06

littlejedi


People also ask

How do you fix exceptions in Java?

The try-catch is the simplest method of handling exceptions. Put the code you want to run in the try block, and any Java exceptions that the code throws are caught by one or more catch blocks. This method will catch any type of Java exceptions that get thrown. This is the simplest mechanism for handling exceptions.

What are the changes made to exception handling from Java 7?

Multi-Catch Exceptions. Multi-catch exceptions have been added to Java SE 7 to facilitate easier and more concise exception handling. To migrate your exception handling code from pre-Java SE 7 code to Java SE 7 code read on.

How do you write an exception in Java?

All exceptions must be a child of Throwable. If you want to write a checked exception that is automatically enforced by the Handle or Declare Rule, you need to extend the Exception class. If you want to write a runtime exception, you need to extend the RuntimeException class.

How do you pass an exception as a parameter in Java?

To throw an exception, we generally use the throw keyword followed by a newly constructed exception object (exceptions are themselves objects in Java). Most exception constructors will take a String parameter indicating a diagnostic message.


1 Answers

"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?

like image 121
Boann Avatar answered Oct 16 '22 09:10

Boann