/** * @author wangyunhan * @throws Exception */ public static void main(String[] argßs) throws Exception { testAbove(); } public static void testException() throws Exception { try { System.out.println(10%0); }catch(ArithmeticException r) { System.out.println("Catch function exception" + r.toString()); } catch (Exception e) { throw new Exception("testException()方法出现异常"+e.toString()); } } public static void testAbove() throws Exception { try { testException(); System.out.println("execute test above "); }catch(Exception e) { throw new Exception("testAbove()方法执行出现异常"+e.toString()); } }
以上代码的执行结果
catchjava.lang.ArithmeticException: / by zero test above execute
分析:
- 一个方法捕获多个异常,异常如果已经被catch,则后面catch不执行
- 异常如果已经被catch并且不抛出异常,则方法不抛出异常