← Java Programming learning pathJava Programming · Module 9 of 10
Exceptions
Handle errors with try, catch, finally and throw.
📖 Key ideas
- An exception is an error event that interrupts normal flow.
- try { } catch (Exception e) { } handles it.
- finally always runs (for cleanup).
- Checked exceptions (IOException) must be handled or declared with throws.
- Unchecked exceptions (NullPointerException) come from bugs.
💡 Real-life example: try/catch is a safety net under a trapeze: the show continues even if someone slips.
tryCode that might fail
catchHandles an exception
finallyAlways runs
throwsDeclares exceptions a method may throw