쉬울 수도 있지만 왜 출력이 1로 오는지 이해할 수 없습니다. 4. 9 행의 return 문의 기능은 무엇입니까?왜 그런 결과가 나오나요?
public static void main(String[] args) {
try{
f();
} catch(InterruptedException e){
System.out.println("1");
throw new RuntimeException();
} catch(RuntimeException e){
System.out.println("2");
return; \\ Line 9
} catch(Exception e){
System.out.println("3");
} finally{
System.out.println("4");
}
System.out.println("5");
}
static void f() throws InterruptedException{
throw new InterruptedException("Interrupted");
}
미리 감사드립니다.
'try'가없고 9 행이 실행되지 않아 런타임 예외가 catch되지 않습니다. – Narmer
또한'RuntimeException'은 검사되지 않은 예외이기 때문에 5가 인쇄되지 않을 것이므로 내부적으로 (try-catch 블록이 없으면) catch되고'System.out.println ("5"); 앞에 프로그램이 종료됩니다. – Narmer