-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChapter39.java
More file actions
41 lines (29 loc) · 986 Bytes
/
Chapter39.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
package chapter39;
class AgeException extends Exception{
//기본생성자
AgeException(){ }
//일반생성자
AgeException(String message){
super(message);
}
}
public class ExceptionEx {
public static void ticketing(int age) throws AgeException{
if(age<0) {
//AgeException 클래스 객체 생성
AgeException e = new AgeException("나이 입력이 잘못되었습니다.!!!");
throw e;
//throw new AgeException("나이 입력이 잘못되었습니다.!!!");
}
}
public static void main(String[] args) {
int age = -10;
//ticketing(int age) 함수 호출 :throws로 떠넘긴 예외 처리 : 여기레에서 catch : 여기에 catch 처리 해주기
try{
ticketing (age);
}catch(AgeException e) {
//System.out.println(e.getMessage());
e.printStackTrace();
}
}
}