| Source code: Catch01.java |
public class Catch01 {
public static void main(String[] args) {
String s = "NOT an Integer";
try {
int i = Integer.parseInt(s);
// this line of code will never be reached
System.out.println("int value = " + i);
}
catch (NumberFormatException nfe) {
System.out.println("The string \""+ s + "\" is not a numeric value");
// for a stach trace: nfe.printStackTrace();
}
}
}
|