日期:2014-05-20 浏览次数:20730 次
public class WithReturn{ public int methodA(int money) throws SpecialException{ if(--money<=0) throw new SpecialException("Out of money!!"); return money; } public int methodB(int money){ try{ System.out.println("Begin"); int result=methodA(money); //此处可能抛出异常 return result; }catch(SpecialException e){ System.out.println(e.getMessage()); return -100; }finally{ System.out.println("Finally"); } } public static void main(String[] args){ System.out.println(new WithReturn().methodB(1)); } }
public static int test(){ int a=0; try{ return a; }finally{ a=1; } } public static void main(String[] args) throws Exception{ System.out.println(test()); }