- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChapter39.java
More file actions
Latest commit
41 lines (29 loc) · 986 Bytes
/
Copy pathChapter39.java
File metadata and controls
41 lines (29 loc) · 986 Bytes
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
32
33
34
35
36
37
38
39
40
41
packagechapter39;
classAgeExceptionextendsException{
//기본생성자
AgeException(){ }
//일반생성자
AgeException(Stringmessage){
super(message);
}
}
publicclassExceptionEx {
publicstaticvoidticketing(intage) throwsAgeException{
if(age<0) {
//AgeException 클래스 객체 생성
AgeExceptione = newAgeException("나이 입력이 잘못되었습니다.!!!");
throwe;
//throw new AgeException("나이 입력이 잘못되었습니다.!!!");
}
}
publicstaticvoidmain(String[] args) {
intage = -10;
//ticketing(int age) 함수 호출 :throws로 떠넘긴 예외 처리 : 여기레에서 catch : 여기에 catch 처리 해주기
try{
ticketing (age);
}catch(AgeExceptione) {
//System.out.println(e.getMessage());
e.printStackTrace();
}
}
}