본문 바로가기

콩's EDUCATION/콩's JAVA_RUN

finally 처리

finally는 항상 출력


 

public class ExceptionTest {
 public static void main(String[] args) {
  try{
  int i = Integer.parseInt(args[0]);
  int j = Integer.parseInt(args[1]);
  System.out.println(i/j);
  }catch (Exception e) {
   System.out.println("항상동일하게 처리합니다");
   return; // 메소드 중단, 없으면 "완료" 표시된다.
   //system.exit(0) // 클래스 수행종료. finally 내부 선언되지 않는다. 

}finally{
   System.out.println("항상 출력됩니다.");
  }
  System.out.println("");
  System.out.println("완료");
 }
}

 

결과

 

항상동일하게 처리합니다
항상 출력됩니다.


 

ExceptionTest.java