Checked vs Unchecked Exceptions
Compile-time vs runtime exceptions
Interview Relevant: Common interview question
6 min read
Checked vs Unchecked Exceptions
Checked exceptions are verified at compile time, unchecked at runtime.
Code Examples
Checked vs unchecked example
java
1
2try {
3 FileReader fr = new FileReader("a.txt"); // Checked
4} catch (IOException e) {}
5
6int x = 10 / 0; // Unchecked
7 Use Cases
- API contracts
- Runtime safety
Common Mistakes to Avoid
- Confusing Error with Exception
- Catching RuntimeException unnecessarily