Java异常
异常
Throwable(异常的父类或超类)
Error(错误)
Exception(异常)
RuntimeException(运行时异常)
非RuntimeException(编译时异常)
异常的处理方法
1.thorws
2.try...catch...finally
Throws
throws作用于方法上,在方法的形参列表括号之后,throws后面加抛出异常的类,可以是多个。
public void method(String name) throws Exception {
........
}
try...catch...finally
格式:
try{
可能会出现异常的代码块;
}catch( Exception e ){
处理操作;
}finally{
后续操作,一般会关闭一些资源操作;
}
try...catch...finally 格式不固定,可以有零或多个catch,当有零个catch块时,后面必须有finally;当有大于零个catch时,finally可以有也可以没有。

浙公网安备 33010602011771号