JAVA/예외( exception )
-
나만의 예외만들기JAVA/예외( exception ) 2023. 6. 15. 18:19
개념 예외를 처리하기 위한 방법으로 2개의 키워드를 알아야 한다. throws : 발생할 수 있는 예외를 등록하는 키워드. throw : 예외가 발생했을 때 예외를 핸들링하지 않으면 해당 메소드를 호출한 곳으로 예외를 보내는 키워드 또한 나만의 예외를 만들기 위해선 새로만든 예외클래스는 Exception을 상속 받아야한다. 점수입력하는 프로그램의 예외처리 클래스 만들어 활용하기 1. 예외처리 클래스 만들기 // 우리가 만드는 예외 클래스 // Exception 또는 RuntimeException 클래스를 상속 받아서 만듬 public class ScoreException extends Exception { // 생성자 public ScoreException(){ super("점수 입력 오류"); // 부..