public class Test {
public static void main(String[] args) {
int arg1;
int result;
String s="abc";
// String s="12";
try {
arg1 = Integer.parseInt(s);
result = arg1 /0;
System.out.println("try中完成finish");
}
catch (Exception e) {
System.out.println(e);
}
System.out.println("优雅结束");
}
}
输出结果:
java.lang.NumberFormatException: For input string: "abc"
优雅结束
public class Test {
public static void main(String[] args) {
int arg1;
int result;
// String s="abc";
String s="12";
try{
arg1=Integer.parseInt(s);
result = arg1/0;
System.out.println("try中 完成finish");
}
catch(Exception e){
System.out.println(e);
}
System.out.println("优雅结束");
}
}
输出结果:
java.lang.ArithemticException: /by zero
优雅结束