develog

try catch finally - Flow test 본문

Dev/Java

try catch finally - Flow test

냐옴 2012. 11. 25. 13:56

public class TestMain {


public static void main(String[] args) {

String ret = null;

System.out.println();

System.out.println("-------------------test1");

ret = test1();

System.out.println("ret : " + ret);

System.out.println();

System.out.println("-------------------test2");

ret = test2();

System.out.println("ret : " + ret);

System.out.println();

System.out.println("-------------------test3");

ret = test3();

System.out.println("ret : " + ret);

}

private static String test1() {

System.out.println("start");

try {

System.out.println("try");

} catch (Throwable e) {

System.out.println("catch");

} finally {

System.out.println("finally");

}

System.out.println("end");

return "OK";

}

private static String test2() {

System.out.println("start");

try {

System.out.println("try");

throw new RuntimeException("[ERR]");

} catch (Throwable e) {

System.out.println("catch");

} finally {

System.out.println("finally");

}

System.out.println("end");

return "OK";

}

private static String test3() {

System.out.println("start");

try {

System.out.println("try");

return "OK1";

} catch (Throwable e) {

System.out.println("catch");

} finally {

System.out.println("finally");

}

System.out.println("end");

return "OK";

}

}



-------------------test1
start
try
finally
end
ret : OK

-------------------test2
start
try
catch
finally
end
ret : OK

-------------------test3
start
try
finally
ret : OK1

'Dev > Java' 카테고리의 다른 글

ant 에서 ssh 사용  (0) 2012.12.01
SQL Developer 에러 조치  (0) 2012.11.27
Spring AOP  (0) 2012.11.24
[java] JSP  (0) 2012.11.14
[java] JSTL  (0) 2012.11.14
Comments