Exception 有 受检异常 和非受检异常
受检异常 包括ClassNotFoundException, SQLException, NoSuchMethodException等,受检异常 的特点 :如果没有对受检异常try catch,就必须在方法头对其throws。
public String shouJianyc throws SQLException{
throw new SQLException();
}
非受检异常 也叫 运行时异常RuntimeException NullPointerException, IllegalArgumentException, ArithmeticException
RuntimeException的特点是 系统允许可以不catch(当然也可以人为catch),在运行时碰到就抛出
public String runTimeyc{
throw new NullPointerException("上级试验点不存在");
}
我们平常应该抛出 业务自定义异常 而不是系统异常(运行时异常),这样才对
参看资料