GCGrowCarrer

Exceptions

Locked

Lesson 15 of 60 · Debugging · Medium

PolymorphismNext: Generics

Finish these first:Methods →Or pass the tests below to unlock it now.

1

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.
Key words (tap to learn):
2

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);
}
3

Quick check

Before writing code: What should `Solution.parseOrDefault("12",0)` return when your implementation of Exceptions is working?

4

Your challenge

2 sample tests, 1 hidden

Write static int parseOrDefault(String s, int def).

Stuck? Get a hint (free)
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.

Mastery0%