class InvalidInputException extends Exception {
InvalidInputException() {
super("잘못된 입력입니다");
}
}
class a {
public static void main(String[] args) {
try {
int result = subtract(5,100);
System.out.println(result);
}catch(InvalidInputException e) {
System.err.println(e.getMessage());
}
}
static int subtract(int a, int b) throws InvalidInputException {
if(a < b)
throw new InvalidInputException();
return a - b;
}
}
601쪽의 위와같은 코드부분에서..
궁금한게 있는데요.
메서드 부분에서 try~catch 구문으로 에러를 처리하는 것과
throws로 메서드를 호출한 부분에서 에러 처리하는 것은 무슨 차이가 있는지 궁금합니다.
각기 어떤 장단점이 있는지.. 설명을 좀 해주셨으면 합니다.
잘 이해가 안되네요.
그럼 답변 부탁드리겠습니다.