WON.dev
chapter08 : exception 본문
package org.joonzis.ex;
// 예외 클래스 : Exception을 상속 받아서 만든다(Custom Exception)
// 예외 클래스를 만드는 이유 : 사용자 친화적인 예외 메세지로 변경 가능.
// 예외가 아닌 것도 예외로 만들 수 있다.
class MyException extends Exception{
// 경고 없애려고 넣은거니까 신경쓰지말자 당장은
private static final long serialVersionUID = 1L;
public MyException(String message) {
super(message);
}
}
public class Ex08_exception {
public static void main(String[] args) {
try {
throw new MyException("내가 만든 예외!");
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
'JAVA > chapter19_exception' 카테고리의 다른 글
Test . exception (0) | 2023.05.30 |
---|---|
chapter09 : exception (0) | 2023.05.30 |
chapter07 : exception (0) | 2023.05.30 |
chapter06 : exception (0) | 2023.05.30 |
chapter05 : exception (0) | 2023.05.30 |