public class Test01 { public static void main(String[] args) { new Test01().device(1,0); } public int device(int a,int b) throws ArithmeticException {//throws用在参数后面 if (b==0){ throw new ArithmeticException();//throw用在方法体中 } System.out.println("有异常"); return a/b; } } /* int a=1,b=0; try { //try是监控区域,监控方法体中的代码是否有异常 System.out.println(a/b); } catch (ArithmeticException e){//catch根据异常的类型是捕获异常 System.out.println("ArithmeticException"); } finally {//用于收尾阶段 System.out.println("异常已捕获"); }*/