package demo01;import java.util.Scanner;public class demo01 {public static void main(String[] args) {int a = 1;int b = 0;try {//try监控区域new demo01().a();if(b==0){throw new ArithmeticException();//主动抛出}}catch(Throwable e){//捕获异常,可以递进捕获System.out.println("Exception");}finally {//善后System.out.println("必执行");}//finally 可用不要,IO流中可以,关闭资源}public void a(){b();}public void b(){a();}//假设在方法中无法处理这个异常,通过throws向上抛出public void test(int a,int b) throws ArithmeticException{if(b==0){throw new ArithmeticException();//方法里}}}