try catch finally

package youxia;

public class ShaoNian {
	public String testException() {
		try {
			throw new RuntimeException("hehe");
		} catch (Exception e) {
			return "catch";
		}finally {
			return "finally";
		}
	}
	
	public static void main(String[] args) {
		ShaoNian shaoNian=new ShaoNian();
		String excp=shaoNian.testException();
		System.out.println(excp);
	}
}

输出结果:

finally

猜你喜欢

转载自my.oschina.net/u/3238650/blog/1788061