• Post Reply Bookmark Topic Watch Topic
  • New Topic

Localized exceptions  RSS feed

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

So I set the default locale as the following.



I then ran some code that contained a message in the exception I expect it to throw (java.lang.IllegalArgumentException).



The message that comes back is still in English. "Illegal Capacity: -7" Even when I call getLocalizedMessage(), it's still in English. Does java have localized strings in the JRE?

Thanks!
 
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

If you look in the installation folder of your JDK, you'll see that there is a file src.zip there. It contains the Java source code of the classes in the standard Java API. I've looked up class Hashtable for you, and the source code of the constructor you're calling looks like this:

So no, the JDK does not provide localized error messages there; the English error message is hard-coded in the source code.

Note: Don't use Hashtable, it's an old legacy collection class. Use HashMap instead.
 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

This is one of the constructors for java.util.HashMap:You can find it inside your Java installation folder, inside the file called src.zip. The exception message is part of the code, and does not appear to have a Locale attached.
 
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, you two...
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote:Oh, you two...
It's usually Rob who beats me by a few minutes like that.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!