首页 > 其他 > 详细

try catch 模块 catch 部分有return 语句处理

时间:2014-11-29 02:14:43      阅读:171      评论:0      收藏:0      [点我收藏+]

?

import java.io.IOException;

/**
 * 
 */

/**
 * @author taoge
 *
 */
public class TestException {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		foo(0);
		foo(1);
	}
	
	public static void foo(int i){
			String str="";
			try {
				if (i==1) {
					throw new IOException();
					
				}
				str+=1;
			} catch (IOException e) {
				// TODO Auto-generated catch block
//				e.printStackTrace();
				str+=2;
				return;
			}finally{
				str+=3;
				System.out.println("test");
			}
			str+=4;
			System.out.println(str);
	}

}

?
test
134
test
?

?

由此可见,当catch 模块遇到return 的时候,在return 之前执行 finally模块语句,然后再执行return

?

try catch 模块 catch 部分有return 语句处理

原文:http://taoge-tony.iteye.com/blog/2161647

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!