스프링

Java - RuntimeException

초롱불 2022. 2. 23. 16:36

RuntimeException is the superclass of those exceptions that can be thrown during the normal operation of the Java Virtual Machine.

 

RuntimeException은 자바 가상 머신이 정상적으로 가동중인 상황에서 던져질 수 있는 예외 상황이다.

 

RuntimeException and its subclasses are unchecked exceptions. Unchecked exceptions do not need to be declared in a method or constructor's throws clause if they can be thrown by the execution of the method or constructor and propagate outside the method or constructor boundary.

 

RuntimeException과 상속받는 클래스들은 unchecked excepion이다. unchecked exception은 메서드나 생성자에서 throws절로 선언될 필요가 없다. 만약 메서드나 생성자로부터 던져질 수 있고 전파될 수 있다면.

 

 

예외 정리

위에서 RuntimeException과 그 서브클래스들만이 unchecked Exception이다. Checked Exception은 try/catch 하지 않는다면 컴파일 에러를 내뱉는다. Unchcked Exception은 catch하는지 확인하지 않기에 컴파일 시점에 예외가 발생하는지 여부를 판단할 수 없다. 물론 (try/catch)처리를 한다고 해도 문제는 없다. 이렇듯 강제성이 없기에 개발에 보다 유연하게 활용될 여지가 있다.