直接上代码
public class TestException { public static void main(String[] args) { try{ myException0(); System.err.println(myException1()); }catch (Exception e){ try{ System.err.println(myException3()); }catch (Exception e1){ System.err.println(e1.getMessage()); } } } public static void myException0(){ System.out.println("0"); } public static String myException1() throws Exception{ try{ int i = 1/0 ;//这里产生了异常,但是进行了try catch处理 System.err.println("1"); }catch (Exception e){ return "len1"; } return "len0"; } public static void myException2(){ int i =1/0 ; System.err.println("2"); } public static String myException3() throws Exception{ try{ int i = 1/0; System.out.println("3"); }catch (Exception e){ throw new Exception("throw new Exception"); } return "len3"; } }
方法myException1()中产生了异常并向调用处抛出了异常,但是又在方法内进行了try catch处理,所以,异常已经处理完成,程序在方法内结束。
执行结果
0
len1