Saturday, May 14, 2011

NumberFormatException

NumberFormatException is often thrown while converting a string value to a numeric value. The exception is thrown when the string can not be converted to a valid number. For example the string "1234" can be converted to an int value as follows:

int num=Integer.parseInt("1234");

What about the string "12xy"? This can not be converted to a number, hence the NumberFormatException will be thrown while executing the below statement:

int num=Integer.parseInt("12xy");

In short the NumberFormatException is thrown to indicate that an attempt is made to convert a string to a number but the string is not in appropriate format.


No comments:

Post a Comment