Skip to content
Learn Netverks

Lesson

Step 25/36 69% through track

checked-unchecked

Checked vs unchecked exceptions

Last reviewed May 28, 2026 Content v20260528
Track mode
server_compiled
Means
Compiled runner
Reading
~1 min
Level
intermediate

This lesson

This lesson teaches Checked vs unchecked exceptions: the syntax, APIs, and habits you need before advancing in Java.

Teams ship Checked vs unchecked exceptions on every Java codebase—skipping it leaves gaps in debugging and code reviews.

You will apply Checked vs unchecked exceptions in contexts like: Spring Boot APIs, banking systems, Android (with Kotlin), and batch/data pipelines on the JVM.

Write Java with a public class (lessons use Main), click Run on server—the dev runner runs javac then java; fix compile errors from stderr (LEARNING_RUNNER_ENABLED=true).

When you can explain the previous lesson's ideas without copying starter code.

Unchecked exceptions extend RuntimeException—compiler does not force handling (NullPointerException, IllegalArgumentException). Checked exceptions extend Exception (but not RuntimeException)—callers must catch or declare with throws.

Checked example

void readFile() throws IOException {
    // ...
}

Design guidance

Use checked exceptions for recoverable, expected failures callers should handle. Many modern APIs prefer unchecked exceptions for cleaner code—Spring and many libraries lean runtime exceptions for non-recoverable programming errors.

Important interview questions and answers

  1. Q: Why checked exceptions exist?
    A: Force explicit handling of recoverable conditions at compile time—debated in modern Java style.
  2. Q: Is NullPointerException checked?
    A: No—it is unchecked (RuntimeException subclass).

Self-check

  1. What keyword declares a method may throw an exception?
  2. Name one checked and one unchecked exception.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • When declare throws?
  • RuntimeException examples?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump