throws与throw关键字。

使用throws声明的方法表示此方法不处理异常,而是交给方法的调用处进行处理;

public class Math {
public int div(int i,int j)throws Exception{
System.out.println("********计算开始********");
int temp = 0;
try {
temp = i/j;
} catch (Exception e) {
e.printStackTrace();
} finally {
System.out.println("********计算结束********");
}
return temp;
}
}

--------------------------------------------------------------
public class ThrowsTest {
public static void main(String[] args) {
Math m = new Math();
try {
System.out.println(m.div(0,0));
} catch (Exception e) {
e.printStackTrace();
}
}
}

throw可以直接抛出一个异常,抛出时直接抛出异常类的实例化对象即可。 

原文地址:https://www.cnblogs.com/wangffeng293/p/13389819.html