NumberFormatException is a type of RuntimeException which is generated when a programmer try to convert String into integer.
Number Format Exception
In this section you will learn about Number Format Exception in java. NumberFormatException is derived from RuntimeException class, generally when a programmer tries to attempt to convert a string into integer which is not appropriate. A NumberFormatException in java occur when trying to convert a string into a number.
public class NumberFormarException { public static void main(String args[]) { int in=Integer.parseInt("10"); System.out.println("Example = " +in ); } }
In the above code we are trying to convert a string value 10 to int . but when we are trying to pass a value "Rose India " to integer.parseInt() method it will raise a compile time error. Because a "Rose India" is not a legal string representation of an int value.
public class NumberFormarException { public static void main(String args[]) { int in=Integer.parseInt("Rose India"); System.out.println("Example = " +in ); } }
After compiling this above code the compile time error is like as follows: