JAVA/예외처리

예외 던지기 throws

별초롱언니 2025. 5. 13. 10:52

예외 던지기란 예외가 발생했을 경우 현재 메서드가 예외를 처리하지 않고 자신을 호출한 쪽으로 예외 처리에 대한 책임을 넘기는 것입니다. 

package chapter09;

public class exam65 {

	public static void methodA() throws Exception{
		methodB();
	}
	public static void methodB() throws Exception{
		methodC();
	}
	public static void methodC() throws Exception{
		Exception e = new Exception();
		throw e;
	}
	
	public static void main(String[] args) {
		try {
			methodA();
		} catch(Exception e	) {
			System.out.println("메인에서 처리");
		}
	}

}

 

 

'JAVA > 예외처리' 카테고리의 다른 글

사용자 정의 예외  (0) 2025.05.13
예외 발생 throw  (0) 2025.05.13
객체로서의 예외  (0) 2025.05.13
finally문  (0) 2025.05.13
예외(Exception) / 예외처리(Exception Handling) / try-catch / finally  (0) 2025.05.12