异常
Exception异常
1.异常处理
try关键字用来监控
catch用来捕获异常
finally处理善后工作
throw主动抛出异常(在方法中)
throws主动抛出异常(在方法上)
eg.
public class Test {
public static void main(String[] args) {
int a=1;
int b=0;
try{//try监控区域
System.out.println(a/b);
}catch (ArithmeticException e){//catch 捕获异常
System.out.println("程序出现异常");
}finally {//处理善后工作 (可无)
System.out.println("finally");
}
}
}
浙公网安备 33010602011771号