티스토리 뷰
Exception 클래스를 상속받는 사용자 예외 클래스 작성
예외 발생 시 예외를 새로운 객체에 던짐
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class UserException {
public static void main(String arg[]) {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
try {
System.out.println("하나의 숫자를 입력하세요 ");
int score = Integer.parseInt(in.readLine());
if (score < 0) {
throw new UserException1("점수가 너무 작음");
} else if (score > 100) {
throw new UserException2("점수가 너무 큼");
}
System.out.println("정상적인 점수 입력");
} catch (UserException1 e) {
System.out.println("UserException1 처리 루틴");
System.out.println(e + "발생");
} catch (UserException2 e) {
System.out.println("UserException2 처리 루틴");
System.out.println(e + "발생");
} catch (Exception e) {
System.out.println("모든 예외 처리 루틴");
System.out.println(e + "발생");
}
}
}
class UserException1 extends Exception {
public UserException1(String message) {
super(message);
}
}
class UserException2 extends Exception {
public UserException2(String message) {
super(message);
}
}
결과 :
하나의 숫자를 입력하세요
128
UserException2 처리 루틴
UserException2: 점수가 너무 큼발생
'java,web study > 2주차 (7월 8일~14일)' 카테고리의 다른 글
객체 할당 (0) | 2013.07.14 |
---|---|
Assertion (0) | 2013.07.14 |
오라클 설치 (0) | 2013.07.12 |
예외처리 03 (0) | 2013.07.11 |
예외처리 02 (0) | 2013.07.11 |
- Total
- Today
- Yesterday
- 청주
- db
- 오라클
- 클래스
- 잡담
- JQuery
- 알고리즘
- 파이썬
- 안드로이드
- 데이터베이스
- SVN
- 자바
- HTML
- jsp
- SQL
- 정보
- 정렬
- CSS
- 아두이노
- 게임
- 프로젝트
- 도전과제
- 충북대
- 졸업작품
- 자바스크립트
- 메모장
- 이론
- 소켓
- 배열
- ERP
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |