1.常见异常
算术异常:ArithmeticException
输入不匹配异常:InputMismatchException
类型转换异常:ClassCastException
数组越界异常:ArrayIndexOutOfBoundsException
空指针异常:NullPointerException
非法参数异常:IllegalArgumentsException
下标越界异常:IndexOutOfBoundsException
文件未找到异常:FileNotFoundException
输入输出异常:IOException
数据库异常:SQLException
数值格式化异常:NumberFormatException
2.处理异常
try{}catch(异常类型 e){}finally{}
3.finally和return
在无返回值方法中,return会在对finally的访问后执行
在有返回值的方法中,如果finally中有return 值,那么一定会执行finally的return
如果finally中没有没有return,也在return再访问finally
4.异常的体系结构
Throwable -->Error
-->Exception-->Unhandled Exception(checked异常)
-->RuntimeException(运行时异常)
5.throw和throws
throw用来生成异常对象,一般要和throws搭配使用
throws是用来声明异常类型
6.自定义异常类型
先继承已知的异常类型,一般是Exception或RuntimeException
然后用super引用父类的有参构造(String message)
1328

被折叠的 条评论
为什么被折叠?



