throws
- 在方法上抛出异常,只管抛出不做处理,谁调用谁处理
- 可以抛出多个异常,跟在方法后面,用逗号隔开
- 方法不一定产生异常,只是可能出现异常,预防处理
public static void say() throws NullPointerException,ClassCastException{
}
throw
- 在方法内程序员主动抛出异常
- 只能抛出一个
- 抛出的异常自己处理或再次抛出或任其产生异常
public static void say(int a) throws Exception{
if(a==2){
throw new NullpointerException();
}
}