关于Java异常处理机制的深入理解 1 引子 try…catch…finally 恐怕是大家再熟悉不过的语句了,而且感觉用起来也是很简单,逻辑上似乎也是很容易理解。不过,我亲自体验的“教训”告诉我,这个东西可不是想象中的那么简单、听话。不信?那你看看下面的代码,“猜猜”它执行后的结果会是什么?不要往后看答案、也不许执行代码看真正答案哦。如果你的答案是正确,那么这篇文章你就不用浪费时间看啦。 package myExample.testException; public class TestException { public TestException() { } boolean testEx() throws Exception{ boolean ret = true; try{ ret = testEx1(); }catch (Exception e){ System.out.println("testEx, catch exception"); ret = false; throw e; }finally{ System.out.println("testEx, finally; return value="+ret); return ret; } } boolean testEx1() throws Exception{ boolean ret = true; try{ ret = testEx2(); if (!ret){ return false; } System.out.println("testEx1, at the end of try"); return ret; }catch (Exception e){ System.out.println("testEx1, catch exception"); ret = false; throw e; } finally{ System.out.println("testEx1, finally; return value="+ret); return ret; } } boolean testEx2() throws Exception{ boolean ret = true; try{ int b=12; int c; for (int i=2;i>=-2;i--){ c=b/i; System.out.println("i="+i); } return true; }catch (Exception e){ System.out.println("testEx2, catch exception"); ret = false; throw e; } finally{ System.out.println("testEx2, finally; return value="+ret); return ret; } } public static void main(String[] args) { TestException testException1 = new TestException(); try{ testException1.testEx(); }catch(Exception e){ e.printStackTrace(); } } } 你的答案是什么?是下面的答案吗? i=2 i=1 testEx2, catch exception testEx2, finally; return value=false testEx1, catch exception testEx1, finally; return value=false testEx, catch exception testEx, finally; return value=false 如果你的答案真的如上面所说,那么你错...