티스토리 뷰
// try : 예외발생 예상지역을 묶고 // catch : 그 지역을 잠그고 // finally : 예외발생과 무관하게 실행...
import java.io.*; public class _4_3 { public static void main(String[] ar) throws IOException{ BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int su1=0, su2=0, tot=0; try{ // 예외 예상지역을 묶고... System.out.print("su1 = "); su1=Integer.parseInt(in.readLine()); System.out.print("su2 = "); su2=Integer.parseInt(in.readLine()); tot = su1/su2; System.out.println("tot = "+tot); } catch(NumberFormatException e) { // 발생된 에러를 e 객체에 담는다 System.out.println("숫자 포맷이..."); System.exit(0); } catch(ArithmeticException e){ System.out.println("0은 안돼!!!.."); System.exit(0); } finally{ System.out.println("처리완료"); // 무조건 실행. } } }
'dev > java' 카테고리의 다른 글
[16] Text(2바이트) 기반 입력 (0) | 2008.09.29 |
---|---|
[16] Text(2바이트) 기반 출력 (0) | 2008.09.29 |
[15] 예외 발생 시키기 (0) | 2008.09.29 |
[15] Thread의 동기화(synchronize) 문제 (0) | 2008.09.29 |
[15] Thread 이용해서 시간출력.. ㅎㅎ (0) | 2008.09.29 |
공지사항