Skip to content
Learn Netverks

Lesson

Step 24/36 67% through track

errors-go

Errors in Go

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

This lesson

This lesson teaches Errors in Go: the syntax, patterns, and safety habits you need before advancing in Go.

Errors as return values, not exceptions—wrapping with %w is standard in production Go.

You will apply Errors in Go in contexts like: Kubernetes ecosystem tools, cloud APIs, and CLI utilities.

Write Go in main.go with package main and func main(), click Run on server—the dev runner runs go run main.go; use fmt.Println for output (requires Go toolchain; LEARNING_RUNNER_ENABLED=true).

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

Go treats errors as values implementing error—not exceptions like Java. Functions return (T, error); callers check explicitly.

Creating and wrapping errors

if err != nil {
    return fmt.Errorf("read config: %w", err)
}

errors.Is and errors.As inspect error chains. panic is for programmer bugs, not expected failures.

Custom errors

Types implementing Error() string can carry extra fields. Keep error messages actionable for operators and logs.

Important interview questions and answers

  1. Q: Exceptions in Go?
    A: No—use explicit error returns; panic/recover only for truly exceptional paths.
  2. Q: %w in fmt.Errorf?
    A: Wraps errors for errors.Is/As chain inspection.

Self-check

  1. What interface do errors implement?
  2. When is panic appropriate?

Tip: Wrap with %w and inspect with errors.Is/errors.As—preserve error chains for logging and API mapping.

Interview prep

Exceptions in Go?

No—return error values; panic for programmer bugs, not expected failures.

%w in fmt.Errorf?

Wraps errors for errors.Is and errors.As chain inspection.

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

  • errors.Is?
  • fmt.Errorf %w?

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