publicclassTest{publicstaticvoidmain(String[] args){int a =1;int b =0;//假设要捕获多个异常:从小到大!try{//try监控区域System.out.println(a / b);}catch(Error e){//catch(想要捕获的异常类型!) 捕获异常System.out.println("Error");}catch(Exception e){System.out.println("Exception");}catch(Throwable t){System.out.println("Throwable");}finally{//处理善后工作System.out.println("finally");}//可以不要finall IO、资源相关的东西,关闭的操作放到在finally里}}publicclassTest2{publicstaticvoidmain(String[] args){int a =1;int b =0;//Ctrl + Alt + T:快捷键捕获异常try{System.out.println(a/b);}catch(Exception e){
e.printStackTrace();//打印错误的栈信息}finally{}}}