I am just trying my hands around with java.util.Currency
, but for few currency codes its throwing me java.lang.IllegalArgumentException
this is my simple code
java.util.Currency c = java.util.Currency.getInstance(code);
as per java doc
public static Currency getInstance(String currencyCode)
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 am getting this exception for few codes and few of them are
as per ISO_4217, all above codes are official ISO 4217 currency names, i am not sure why i am getting this exception in this case? Do i need to do something else or need to pass some other information to JVM to get correct values? any help to clear my confusion is really appreciable or can point me to the ISO 4217 currency which java doc is pointing as i can see above codes in ISO 4217 list so its possible i am looking at wrong documents/references.
In order to provide more insights here is the 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)
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)
This is an interesting problem.
Both COU and UYI are not real currencies. COU is the old Venezuelan currency (not in use anymore) and UYI is an indexed currency, probably used by banks to sort out exchange rates.
In java 1.7.0_u7, the currecy TMT works fine. TMT was introduced in 2009, so it makes sense that Java 6 doesn't know that code.
For Uruguay UYU
is working fine instead of UYI
and COP
instead of COU
for Columbia TMT
is not working for me also.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With