Skip to content

Commit 82c3c8b

Browse files
authored
Update exceptions.md
1 parent b82266e commit 82c3c8b

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

exceptions.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,29 @@ try (Resource1 res1 = new Resource1();
290290

291291
**Key Rule:** Exceptions thrown in **catch blocks are NOT caught** by subsequent catch blocks in the same try-catch structure. Only exceptions from the **try block** can be caught.
292292

293+
**📚 Exception Hierarchy Reminder:**
294+
```java
295+
java.lang.Throwable
296+
├── java.lang.Error (unchecked - JVM errors, don't catch)
297+
└── java.lang.Exception
298+
├── java.lang.RuntimeException (unchecked - programming errors)
299+
│ ├── IllegalArgumentException
300+
│ ├── NullPointerException
301+
│ ├── IndexOutOfBoundsException
302+
│ └── IllegalStateException
303+
└── Checked Exceptions (must handle or declare)
304+
├── IOException
305+
├── SQLException
306+
├── FileNotFoundException (extends IOException)
307+
└── ClassNotFoundException
308+
```
309+
310+
**Exception Classification Rules:**
311+
- **Checked Exception:** Any exception that extends `java.lang.Exception` but is NOT a subclass of `java.lang.RuntimeException`
312+
- **Unchecked Exception:** Any exception that extends `java.lang.RuntimeException` (or `java.lang.Error`)
313+
- **Checked exceptions** must be handled with try-catch OR declared with `throws`
314+
- **Unchecked exceptions** can be handled but don't have to be
315+
293316
```java
294317
public class FamilyReunion {
295318
public static void main(String[] args) {

0 commit comments

Comments
 (0)