public class Main {
public static void main(String[] args) {
String str = "10";
int i = Integer.parseInt(str);
System.out.println("Integer after parsing: " + i);
System.out.println("Now parsing string which is not integer");
try {
int j = Integer.parseInt("Not integer");
} catch (Exception e) {
e.printStackTrace(System.out);
}
}
}
Integer after parsing: 10
Now parsing string which is not integer
java.lang.NumberFormatException: For input string: "Not integer"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:580)
at java.lang.Integer.parseInt(Integer.java:615)
at Main.main(Main.java:8)