본문 바로가기

java

Unhandled exception type 에러 처리 (Exception)

책에 있는 throw 문을 작성 중에 Unhandled exception type message가 떳다.

Java 문법 문제 인 것 같아서 구글링 해보니, 다른 분이 친절하게 정리해주셨다.
해결 방법은 다음과 같다.

1. try - catch 문으로 error handling 하기,
2. method에 throws Exception 을 추가하여 해당 함수가 Exception을 발생 시킬 수 있다고 명시해주기.

Compile time에 해당 error를 처리하는 이유는 reference에 나와있다.

 This compile-time checking for the presence of exception handlers is designed to reduce the number of exceptions which are not properly handled

적절하게 처리되지 못하는 error의 수를 줄이기 위해 compile time에 처리한다고 한다.

 

참고
https://docs.oracle.com/javase/specs/jls/se8/html/jls-11.html
https://way-be-developer.tistory.com/112