try catch 모듈 catch 부분에return 문장 처리가 있습니다

1388 단어
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을 실행합니다

좋은 웹페이지 즐겨찾기