异常处理 try-catch 以及 try-catch-finally try{ //一些会抛出异常的方法 }catch(Exception e){ //处理该异常的代码块 }catch(Exception2 e){ //处理Exception2的代码块 }…(n个catch块)…{ }finally{ //最终将要执行的一些代码 } Exception顺序问题 先子类后父类
package cn.beepower.ning; /** * Created by NingDaolong on 2016/8/16. */ public class Test { public static void main(String[] args) { Test test = new Test(); int tre = test.tre(); System.out.println("tre = " + tre); } /** * @return */ public int tre() { int di = 10; int res = 100; try { while (di > -1) { di--; res = res + 100 / di; } return res; } catch (ArithmeticException e) { System.out.println("算术异常"); e.printStackTrace(); return -1; } catch (Exception e) { System.out.println("异常"); e.printStackTrace(); return -2; } } } 向上抛出异常自定义异常总结 -转载简易扑克牌 http://blog.csdn.net/qq_31028891/article/details/52122980
