Exceptions
LockedLesson 15 of 60 · Debugging · Medium
Finish these first:Methods →Or pass the tests below to unlock it now.
The big idea
Checked exceptions must be declared or caught; unchecked (RuntimeException) need not be. Use try-with-resources for AutoCloseable.
Think of it like this: Think of debugging and error handling like a backup generator and circuit tester: `try/except` catches faults smoothly while tracing inputs reveals exactly where state diverged.
Read the lesson
Checked exceptions must be declared or caught; unchecked (RuntimeException) need not be. Use try-with-resources for AutoCloseable.
try (var r = Files.newBufferedReader(path)) {
return r.readLine();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Quick check
Before writing code: What should `Solution.parseOrDefault("12",0)` return when your implementation of Exceptions is working?
Your challenge
Write static int parseOrDefault(String s, int def).
More learning tools(compare languages, visual guide, related lessons)
Compare with another language
Similar to javascript.error-handling (80% overlap). Error handling: try/catch in Python/Java/JS/C++ vs explicit (val, err) in Go and Result<T, E> in Rust.
Visual walkthrough
A diagram, a step-by-step animation, and short captions for Exceptions.
Learn this first
- MethodsNot yet