Java
-
혼공자 : ch10 예외처리Java 2023. 2. 23. 11:02
10-2 예외처리 예외 : 사용자 조작 실수, 개발자 코딩 문제 발생 오류 예외가 발생하면 프로그램 종료. > 정상 실행 상태 유지를 위해 예외처리 예외 처리 코드 예외 처리 코드 : try - catch - finally 블록 try 블록에는 예외 발생 가능 코드가 위치한다. try 블록의 코드가 예외 발생 없이 정상 실행되면 catch() 블록의 코드를 스킵하고 finally 블록의 코드를 실행한다. 만약 try 블록에서 예외가 발생하면 즉시 실행을 멈추고 catch() 블록으로 이동하여 예외 처리 코드를 실행한다. 그리고 finally 블록의 코드를 실행한다. finally 블록은 생략 가능하며, 예외 발생 여부와 상관없이 항상 실행할 내용이 있을 경우에만 finally 블록을 작성해준다. 심지어 ..