Exception
class excluding RuntimeException
.
RuntimeException
and all Error
classes.
Aspect | Checked Exception | Unchecked Exception |
---|---|---|
Also Called | Compile-Time Exceptions | Runtime Exceptions |
Definition | Checked Exceptions are those which are checked at compile-time by compiler | Unchecked Exceptions are those which are ignored by compiler and checked at runtime by JVM |
Hierarchy | Comes under the Exception class,(excluding RuntimeException ) |
Comes under the RuntimeException class |
Examples | IOException , SQLException |
NullPointerException , ArithmeticException |
Handling | Must handled by try-catch or declared using throws keyword |
Optional to handle (but recommended) |
When occur | External factors (eg. I/O and DB connection) | Code mistakes (eg. null, index, /0) |
Impact | Safe but lengthy | Flexible but risky |
Analogy | Train delay notice | Tire burst |
Best Practice | Always handle or declare checked exceptions properly | Avoid mistakes in code or Check data before use |
Your feedback helps us grow! If there's anything we can fix or improve, please let us know.
Weβre here to make our tutorials better based on your thoughts and suggestions.