public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
int a=4,b=0;
int c = 0;
try {
c=div(a,b);
}
catch(Exception e)
{
//System.out.println("除零啦");
throw e;
}
finally {
System.out.println("over1");
}
System.out.println("over2");
System.out.println(c);
}
public static int div(int a ,int b)
{
return a/b;
}
}
复制代码
一段简单的异常小代码,执行结果:
Exception in thread "main" java.lang.ArithmeticException: / by zero
at Ketangcg.ExceptionDemo.div(ExceptionDemo.java:28)
at Ketangcg.ExceptionDemo.main(ExceptionDemo.java:13)
over1