package com.basic;//예외처리 finally의 사용방법
public class ExceptionEx6 {
public static void main(String[] args){
System.out.println("==예외가 발생하지 않은 경우==");
System.out.println("1");
try{
System.out.println("2");
System.out.println("3");
}catch(Exception e){
System.out.println("4");
}finally{//예외가 있던 없던 무조건 실행됨
System.out.println("5");
}
System.out.println("프로그램 종료");
}
}==예외가 발생하지 않은 경우==
package com.basic;//예외처리 finally의 사용방법
public class ExceptionEx7 {
public static void main(String[] args){
System.out.println("==예외가 발생한 경우==");
System.out.println("1");
try{
System.out.println("2");
System.out.println(7/0);
System.out.println("3");
}catch(Exception e){
System.out.println("4");
}finally{//예외가 있던 없던 무조건 실행됨
System.out.println("5");
}
System.out.println("프로그램 종료");
}
}
==예외가 발생한 경우==
'Java > Exception Handing' 카테고리의 다른 글
| 예외처리 throws 사용법 (0) | 2012.04.11 |
|---|---|
| 예외처리 다중 catch문 사용하기 (0) | 2012.04.11 |
| 예외처리 5 (0) | 2012.04.11 |
| 예외처리 기본4 (0) | 2012.04.11 |
| 예외처리 기본3 (0) | 2012.04.11 |