I am converting a BigDecimal currency value to a locale specific Currency Format using the Locale(languageCode, countryCode) constructor as shown in the code below
public static String formatCurrency(BigDecimal amount, String languageCode, String countryCode) {
Format format = NumberFormat.getCurrencyInstance(new Locale(languageCode, countryCode));
String formattedAmount = format.format(amount);
logger.debug("Orginal Amount {} and Formatted Amount {}", amount, formattedAmount);
return formattedAmount;
}
Now as per the excellent resource at Oracle Docs
The runtime environment has no requirement that all locales be supported equally by every locale-sensitive class. Every locale-sensitive class implements its own support for a set of locales, and that set can be different from class to class. For example, a number-format class can support a different set of locales than can a date-format class.
Since my languageCode and countryCode are entered by User, how do I handle the situation (or rather how does the NumberFormat.getCurrencyInstance method handle it) when a user enters wrong input like say, languageCode = de and countryCode = US.
Does it default to some Locale ? How does one handle this situation.
Thanks.