☕ Java Beginner

What is the difference between checked and unchecked exceptions?

Answer

Checked exceptions are exceptions that the compiler forces you to handle — either catch them with try-catch or declare them in the method signature using throws. They extend Exception (but not RuntimeException) and represent recoverable conditions like file not found (IOException) or SQL errors (SQLException). Unchecked exceptions (runtime exceptions) extend RuntimeException and do not need to be explicitly handled or declared — they represent programming errors like null pointer access (NullPointerException), array index out of bounds (ArrayIndexOutOfBoundsException), or illegal arguments (IllegalArgumentException). Error classes (like OutOfMemoryError) are also unchecked but represent unrecoverable JVM conditions.