try、catch、finally
ctrl+alt+t为快捷键
public class Demo01 {
public static void main(String[] args) {
int a = 0;
int b = 0;
try { //监控区域
System.out.println(a/b);
}catch (ArithmeticException e) { //捕获异常,括号参数为想要捕获的异常类型
System.out.println("b不能为0");
}finally { //无论是否异常都会执行,处理善后工作
System.out.println("finally");
}
}
}
throw、throws
主动的抛出异常