1. 常见异常:
a.算术异常:ArithmeticException
b.输入不匹配异常: InputMismatchException
c. 类型转换异常: ClassCastException
d. 数组越界异常: ArrayIndexOutofBoundsException
f. 空指针异常: NullPointerException
g. 非法参数异常: IllegalArgumentException
h. 下标越界异常: IndexOutofBoundsException
i. 文件未找到异常: FileNotFoundException
j. 输入输出异常: IOExcep
k. 数据库异常: SQLException
finally和return
无返回值方法中,return会在对finally的访问后执行
有返回值方法中,如果finally中有return值,那么一定会执行finally的return,如果finally中没有return,也会在return后再访问finally
throw和throws
throw一般要和throws搭配使用
异常的体系结构:
Throwable分为Error和Exception
Exception分为RuntimeException(运行时异常,非必须处理的)和Unhandled Excepiton(Checked异常)
处理异常
try{ } catch(异常类型 e){ } finally{ }
自定义异常类型
先继承已知的异常类型,一般是Exception或RuntimeException
然后用super引用父类的有参构造(String message)