public class _Quiz_11 {
public static void main(String[] args) {
int errorCode = 0;
try{
if(errorCode ==0) {
System.out.println("์ํ ๊ตฌ๋งค๋ฅผ ์๋ฃํ์์ต๋๋ค.");
}
else if(errorCode == 1) {
throw new timeOutException("์ํ ๊ตฌ๋งค ๊ฐ๋ฅ ์๊ฐ์ด ์๋๋๋ค.");
}
else if (errorCode == 2) {
throw new soldOutException("ํด๋น ์ํ์ ๋งค์ง๋์์ต๋๋ค.");
}
}catch (timeOutException e){
System.out.println(e.getMessage());
System.out.println("์ํ ๊ตฌ๋งค๋ 20์ ๋ถํฐ ๊ฐ๋ฅํฉ๋๋ค.");
}catch (soldOutException e){
System.out.println(e.getMessage());
System.out.println("๋ค์ ๊ธฐํ์ ์ด์ฉํด์ฃผ์ธ์.");
} catch (Exception e) {
System.out.println(e.getMessage());
System.out.println("๋ชจ๋ ์์ธ๋ฅผ ์ฒ๋ฆฌํฉ๋๋ค.");
}
}
}
class soldOutException extends Exception {
public soldOutException(String message) {
super(message);
}
}
class timeOutException extends Exception {
public timeOutException(String message) {
super(message);
}
}
sold out Exception ์์ธ ๊ฐ์ฒด๋ฅผ ์์ฑํด์ ๋์ง ๋, ํด๋น ์์ธ๋ง ์ ๋ฌธ์ผ๋ก ๋ค๋ฃจ๋ catch๊ฐ ์์ ๊ฒฝ์ฐ ํด๋น catch๊ฐ ์ก์์ ์ฒ๋ฆฌํจ.
์ ์ฒด๋ฅผ ๋ค๋ฃจ๋ Exception e๋ ์ด๋ค ์์ธ๋ฅผ ์ ๋ฌธ์ผ๋ก ๋ค๋ฃจ๋ catch๊ฐ ์์ ๋ ๊ฐ๋ํจ. (์ฐ์ ์์๊ฐ ๋ฎ๋ค.)
0