package demo;
public class Alpha14 {
public static void main(String[] args) throws Exception {
String a = null;
try {
System.out.println(a.charAt(0));
} catch (Exception e) {
e.printStackTrace();
System.out.println();
throw new Exception("空指针异常");
}
}
}
throws 抛出异常后停止 ()
try catch 抛出异常后继续 ()
联合【throws + try catch+throw new 】,可以抛给用户一个自定义的错误信息,方便客户理解。
Error :一般与硬件相关
Exception:一般与程序相关
finally:无论try中是否出现异常,都会执行
父子类异常:
(1)子类可不定义异常
(2)子类异常可与父类相同
(3)子类抛出的异常可为父类异常的子类



