Clean β’ Professional
In Java, exceptions are events that disrupt the normal flow of a program. They are classified into different types based on when they occur and how they should be handled.

Common Examples:
| Exception | Cause |
|---|---|
IOException | File read/write errors |
SQLException | Database access issues |
FileNotFoundException | File does not exist |
ClassNotFoundException | Class not found |
InterruptedException | Thread interruption |
Example:
import java.io.*;
public class CheckedExample {
public static void main(String[] args) throws IOException {
FileReader fr = new FileReader("data.txt"); // Checked Exception
}
}
Common Examples:
| Exception | Cause |
|---|---|
ArithmeticException | Divide by zero |
NullPointerException | Using null object |
ArrayIndexOutOfBoundsException | Invalid array index |
NumberFormatException | Invalid string-to-number conversion |
ClassCastException | Wrong type casting |
Example:
public class UncheckedExample {
public static void main(String[] args) {
int result = 10 / 0; // Runtime Exception
}
}
Common Examples:
| Error | Cause |
|---|---|
OutOfMemoryError | JVM heap memory full |
StackOverflowError | Infinite recursion |
VirtualMachineError | JVM internal failure |
Example:
public class ErrorExample {
public static void recursive() {
recursive(); // Infinite recursion
}
public static void main(String[] args) {
recursive(); // StackOverflowError
}
}
Throwable
β
βββ Exception (Recoverable)
β βββ Checked Exception
β βββ Unchecked Exception (RuntimeException)
β
βββ Error (Non-Recoverable)
| Type | Checked By Compiler? | Occurrence | Examples | Can Handle? |
|---|---|---|---|---|
| Checked | Yes | Compile-time | IOException, SQLException | Yes |
| Unchecked | No | Runtime | NullPointerException, ArithmeticException | Yes |
| Error | No | JVM failure | OutOfMemoryError, StackOverflowError | No |