cannot catch NumberFormatException
807597Mar 9 2005 — edited Jul 27 2006Hi,
Why I cannot catch NumberFormatException?
public class Catch{
public final static void main (String[] args){
try{Integer.parseInt("Not a number");}
catch (Exception e){
System.out.println("1 Contains non numeric data.");
}
try{Integer.parseInt("Not a number");}
catch (NumberFormatException e){
System.out.println("2 Contains non numeric data.");
}
}
}
c:\j2sdk1.4.2\bin\java.exe Catch
1 Contains non numeric data.
Exception in thread "main" java.lang.NumberFormatException: For input string: "Not a number"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:468)
at java.lang.Integer.parseInt(Integer.java:518)
at Catch.main(Catch.java:9)