java. util. Currency. GetInstance throws illegalargumentexception

I just use Java util. Currency to try my hand, but for very few currency codes, it throws my java lang.IllegalArgumentException

This is my simple code

java.util.Currency c = java.util.Currency.getInstance(code);

According to the Java documentation

Returns the Currency instance for the given currency code.

Parameters:
    currencyCode - the ISO 4217 code of the currency 
Returns:
    the Currency instance for the given currency code 
Throws:
    NullPointerException - if currencyCode is null 
    IllegalArgumentException - if currencyCode is not a supported ISO 4217 code.

I get a few codes for this exception, rarely

> UYI > COU > TMT

According to ISO_ 4217, all the above codes are the official ISO 4217 currency name. I don't know why I get this exception in this case? Do I need to do something else, or do I need to pass some other information to the JVM to get the correct value? Any help to clear my confusion is very obvious, or you can point to the ISO 4217 currency pointed by my ISO document. Because I can see the above code in the ISO 4217 list, it may be that I am looking at the wrong document / reference

To provide more insight, here is stack trace

Exception in thread "main" java.lang.IllegalArgumentException
    at java.util.Currency.getInstance(UnkNown Source)
    at java.util.Currency.getInstance(UnkNown Source)
    at CurrencyTest1.main(CurrencyTest1.java:10)

And Java versions

java version "1.6.0_21"
Java(TM) SE Runtime Environment (build 1.6.0_21-b07)
Java HotSpot(TM) 64-Bit Server VM (build 17.0-b17,mixed mode)

Solution

This is an interesting question

Neither cou nor uyi are real currencies Cou is the old Venezuelan currency (no longer used), and uyi is an index currency, which may be used by banks to sort out the exchange rate

In Java 1.7 0_ In U7, TMT works normally TMT was launched in 2009, so it makes sense that Java 6 doesn't know the code

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>