Skip to content
Learn Netverks

Lesson

Step 22/36 61% through track

error-handling

Error handling

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

This lesson

This lesson teaches Error handling: the syntax, APIs, and habits you need before advancing in Rust.

Result and Option replace exceptions—explicit error paths are idiomatic and required in production Rust.

You will apply Error handling in contexts like: Infrastructure CLIs, proxies, game engines, blockchain nodes, and latency-sensitive backends.

Write Rust with fn main(), click Run on server—the dev runner compiles main.rs with rustc and runs the binary; fix borrow errors from stderr (requires Rust toolchain; LEARNING_RUNNER_ENABLED=true).

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

Idiomatic Rust propagates errors with ? inside functions returning Result, and handles locally with match or combinators like map_err.

The ? operator

fn read() -> Result<String, std::io::Error> {
    let s = std::fs::read_to_string("file.txt")?;
    Ok(s)
}

Important interview questions and answers

  1. Q: Exceptions in Rust?
    A: No—recoverable errors use Result; panics for unrecoverable bugs.

Self-check

  1. What does ? do on Err?
  2. When is panic appropriate?

Tip: Use panic! for logic bugs, Result for expected failures like I/O or parsing.

Interview prep

Exceptions in Rust?

No—recoverable errors use Result and ?; panic! is for unrecoverable bugs.

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

  • panic vs Result?
  • expect vs unwrap?

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