NoSuchElementException — 요소가 없을 때의 예외
NoSuchElementException — 요소가 없을 때의 예외
NoSuchElementException은 여러 접근자 메서드가 요청된 요소가 존재하지 않음을 나타내기 위해 던지는 예외예요. 예를 들어 빈 컬렉션에서 next()를 호출하거나, 빈 Optional에서 값을 가져오려 할 때 발생해요.
본문
public class NoSuchElementException extends RuntimeException
Scanner의 InputMismatchException이 이 예외를 확장하기도 해요.
생성자
NoSuchElementException()— 오류 메시지 문자열이null인 예외를 만들어요.NoSuchElementException(String s)— 오류 메시지 문자열s에 대한 참조를 저장해getMessage()로 나중에 가져올 수 있게 해요.NoSuchElementException(Throwable cause)— 지정된 원인으로 만들어요. 상세 메시지는(cause == null ? null : cause.toString())로 설정돼요.NoSuchElementException(String s, Throwable cause)— 지정된 상세 메시지와 원인으로 만들어요.