오류 보충자료
1. 예외 처리가 필요한 이유
2. 예외 처리 예제
(1) 기본적인 예외 처리: 정상 흐름 유지
public class ExceptionExample {
public static void main(String[] args) {
try {
int result = divide(10, 0); // 0으로 나누기 시도
System.out.println("Result: " + result);
} catch (ArithmeticException e) {
System.out.println("Error: Division by zero is not allowed."); // 에러 처리
}
System.out.println("Program continues...");
}
public static int divide(int a, int b) {
return a / b; // ArithmeticException 발생 가능
}
}(2) 에러 발생 시 작업 누적의 문제: 메모리 누수 예제
(3) 서버 과부하 및 메모리 누적 문제
(4) 정상 흐름과 예외 흐름의 혼합 문제
3. 예외 처리에서 로그 활용
4. 자바의 예외 계층 구조
(1) 예외 계층
(2) 예외 계층 다이어그램
(3) 체크 예외와 언체크 예외의 차이점
5. 예외 처리 기본 규칙
(1) 기본 규칙
6. 예외 처리 예제 코드
(1) 체크 예외: IOException 처리
IOException 처리(2) 언체크 예외: NullPointerException 처리
NullPointerException 처리(3) throws를 사용한 예외 전달
throws를 사용한 예외 전달(4) 상위 예외로 처리
(5) Error 예외 예제 (복구 불가능)
Error 예외 예제 (복구 불가능)7. finally 키워드와 반드시 실행되는 블록
finally 키워드와 반드시 실행되는 블록(1) finally 키워드란?
finally 키워드란?(2) finally 사용 예제
finally 사용 예제(3) finally 블록 활용
finally 블록 활용8. 언체크 예외와 체크 예외의 현대적 사용
(1) 언체크 예외 중심 개발
(2) 공통 예외 처리
9. Try-with-resources (자바 7 이상)
(1) try-with-resources란?
try-with-resources란?(2) try-with-resources 예제
try-with-resources 예제(3) AutoCloseable과 close() 오버라이드
AutoCloseable과 close() 오버라이드Last updated