类j20exception继承自类Exception
public class j20exception extends Exception
{
public static void main(String args[])
{
String str1, str2;
int i, j, result;
str1 = new String(args[0]);
str2 = new String(args[1]);
try
{
i = Integer.parseInt(str1);
j = Integer.parseInt(str2);
result = i / j;
System.out.println("result = i / j = " + result);
}
catch (NumberFormatException e)
{
System.out.println("first exception:" + e.getMessage());
}
catch(ArithmeticException e)
{
System.out.println("second exception:" + e.getMessage());
}
finally
{
System.out.println("好像不过怎么样 finally都得执行");
}
}
}
结果如下图