之前很少这样写,所以对这方面的体验很少。现在自己证实了一把,确认throws exception之后,不会有任何的返回。这个感觉有点异样,惭愧,惭愧!!程序直接中断!验证的代码如下:
public class ThrowsException { public String devideByZero() throws Exception { try { int i = 1 / 0; System.out.println("---------------2--------------"); } catch (Exception e) { throw new Exception(); } finally{ System.out.println("---------------finally--------------"); } System.out.println("---------------3--------------"); return "2"; } /** * @param args */ public static void main(String[] args) { ThrowsException te = new ThrowsException(); String kk = null; try { kk = te.devideByZero(); System.out.println(kk); } catch (Exception e) { System.out.println("-------------4---------------"); System.out.println("The third line:"+kk); } System.out.println("The second line:"+kk); } }