Throwable
├─ Error ← 시스템 오류 (보통 안 건드림)
└─ Exception
├─ Checked Exception
└─ RuntimeException (Unchecked Exception)
먼저 자바의 예외 구조를 알아보자.
OutOfMemoryError
StackOverflowError
컴파일 시점에 강제 처리
try - catch 또는 throws 필수
외부 자원, 환경 문제에 많음
// 예
// IOException
// SQLException
// ClassNotFoundException
public void readFile() throws IOException {
FileReader fr = new FileReader("test.txt");
}
// 안 쓰면 컴파일 에러
컴파일러가 강제 안 함
대부분 로직 오류
// NullPointerException
// IllegalArgumentException
// IndexOutOfBoundsException
// ArithmeticException
String s = null;
System.out.println(s.length()); // NPE