These Go error handling questions cover the error type, custom errors, wrapping with %w, errors.Is, errors.As, sentinel errors, panic and recover. We gathered them from public interview lists, coding rounds and community threads. Then we rewrote them in plain words and grouped them by idea.
This post is questions only, so answer each one in your own words first. When you need help, read Go error handling for beginners, Go error wrapping with errors.Is and errors.As and Go panic and recover with defer. Also, finish Part 8 on interfaces first, because error is just an interface with one method.
How to Use These Go Error Handling Questions
Answer each of these Go error handling questions out loud, then write a tiny program to prove your answer. Error bugs often stay quiet until a real failure reaches production. Finally, try the scenario questions, since they come from real outages.
The table below lists each section and its number of questions.
| Section | What it tests | Questions |
|---|---|---|
| Error basics | The error type and the if err != nil style | 13 |
| Creating errors | errors.New, fmt.Errorf and custom types | 14 |
| Wrapping and checking | %w, errors.Is, errors.As and Join | 15 |
| Sentinel vs typed errors | Design choices for callers | 14 |
| Panic, defer and recover | When to crash and how to recover | 14 |
| Errors in real services | Logging, HTTP responses and retries | 10 |
| Error coding tasks | Classic interview programs | 9 |

Go Error Handling Questions on the Basics
Before you answer, study Go error handling for beginners. These Go error handling questions check the habits that every Go developer uses daily.
- What is the error type in Go, and how is it defined?
- Why does Go return errors as values instead of throwing exceptions?
- How does the if err != nil pattern work, and why is it so common?
- Where should the error appear in a list of return values?
- What should a function return for its other values when it fails?
- Why is ignoring an error with the blank identifier risky?
- When is it fine to ignore an error, for example after a failed Close on a read-only file?
- How should an error message look, and why should it start with a lower case letter?
- Why should an error message not end with a full stop or a newline?
- What does it mean to handle an error only once?
- How do you reduce repeated if err != nil checks without hiding errors?
- Scenario: when a function logs an error and also returns it, so the same failure appears five times in the logs, how would you fix it?
- Scenario: when a caller gets a value and an error together, which one should it trust first?
Go Error Handling Questions on Creating Errors
Before you answer, study Go error wrapping. Interviewers use these Go error handling questions to see whether you can pick the right kind of error for each case.
- How do errors.New and fmt.Errorf differ?
- When would you create a custom error type instead of a plain message?
- What method must a custom error type have?
- Should a custom error type use a value receiver or a pointer receiver, and why?
- How can a custom error carry extra data, such as an HTTP status code or a field name?
- Why do two calls to errors.New with the same text create different errors?
- What is the danger of comparing errors by their message text?
- How do you add a stack trace to an error, and does the standard library do it for you?
- Which errors does the standard library expose as variables, for example io.EOF?
- Why is io.EOF not really a failure in most read loops?
- How do you design error messages so that they read well when wrapped many times?
- Can a nil pointer of a custom error type cause trouble when you return it as error?
- Scenario: when a validation function must report which field failed, how would you design its error type?
- Scenario: when users see raw database errors in an API response, what would you change?
Go Error Handling Questions on Wrapping and Checking
Before you answer, study Go error wrapping with errors.Is and errors.As. Since Go 1.13, these Go error handling questions appear in almost every mid level interview.
- What does the %w verb do inside fmt.Errorf?
- How does %w differ from %v when you format an error?
- What is an error chain, and how does errors.Unwrap walk it?
- How does errors.Is decide that two errors match?
- How does errors.As find an error of a given type, and why do you pass a pointer?
- When should a custom error type have its own Unwrap method?
- Can you write an Is method on a custom error, and when does that help?
- What does errors.Join do, and which Go version added it?
- How can one fmt.Errorf call wrap two errors at the same time?
- Why does wrapping an error turn it into part of your public API?
- When would you choose %v on purpose so that callers cannot unwrap the error?
- How do you add context to an error without losing the original cause?
- What is a good wrap message, for example open config file instead of error occurred?
- Scenario: when errors.Is(err, sql.ErrNoRows) returns false even though no rows came back, what would you check first?
- Scenario: when a log line shows the same context words three times in a row, how would you clean up the wrapping?
Sentinel Errors vs Error Types
Before you answer, study Go error handling for beginners again. These questions test design judgement, so explain the trade-off behind each answer.
- What is a sentinel error, and how do you declare one?
- Why do many Go developers prefer few sentinel errors in a public package?
- What are the trade-offs between sentinel errors, error types and opaque errors?
- How does checking behaviour instead of type, for example a Temporary method, help callers?
- When should a package hide its error details from callers?
- How do you name sentinel errors, and why do they usually start with Err?
- Why should you never change the text of an exported sentinel error lightly?
- How do you decide which errors a function documents for its callers?
- How do you map internal errors to HTTP status codes in one place?
- What is the difference between a domain error and an infrastructure error?
- How do you test that a function returns the right sentinel error?
- Why should a library avoid calling log.Fatal or os.Exit?
- Scenario: when a payment client returns ten different error types, how would you make it simpler for callers?
- Scenario: when a service must retry only on network failures, how would you detect them safely?
Go Error Handling Questions on Panic and Recover
Before you answer, study Go panic and recover with defer. These Go error handling questions check when a program should stop and when it should keep going.
- What is a panic, and how does it differ from returning an error?
- When is it right to panic in Go code?
- What happens to deferred calls when a function panics?
- How does recover work, and why must it run inside a deferred function?
- What does recover return when there is no panic?
- Can another goroutine recover a panic that started in a different goroutine?
- How can a deferred function change the error a function returns, using named results?
- Why do Must functions such as regexp.MustCompile panic instead of returning an error?
- Which runtime errors cause a panic, for example an index out of range?
- How does an HTTP server keep running when one handler panics?
- Should you recover from every panic in a worker goroutine, and what are the risks?
- What does panic(nil) do in recent Go versions?
- Scenario: when one bad request crashes the whole service, how would you protect the server?
- Scenario: when a background job panics at night and nobody notices, how would you catch and report it?
Errors in Real Services
Before you answer, study Go retry with backoff and jitter and Go input validation. Real services need more than if err != nil, so these Go error handling questions look at logs, users and retries.
- Where should you log an error, at the lowest level or at the top of the call stack?
- How do you return safe error messages to API users while keeping details in the logs?
- How would you add a request ID to every error log line?
- What errors should a retry loop retry, and which ones should it never retry?
- How do context.Canceled and context.DeadlineExceeded show up as errors?
- How do you collect errors from many goroutines, for example with errgroup?
- What is the cost of creating many errors in a hot loop?
- How would you report validation errors for several fields at once?
- Scenario: when a client times out but the server still finishes the work, what would the logs show, and what would you change?
- Scenario: when an on-call engineer cannot tell which call failed from an error message, how would you improve the messages?
Go Error Handling Questions for Coding Rounds
Before you answer, write each program by hand. Interviewers watch how you wrap, check and return errors, not only whether the code runs.
- Write a function that opens a file, reads it and returns a wrapped error on failure.
- Create a NotFoundError type with an ID field, then check it with errors.As.
- Write a safe divide function that returns an error for a zero divisor.
- Convert a panic into an error with defer and recover.
- Write a retry helper that tries a function three times with a short sleep.
- Validate a user struct and return all field errors with errors.Join.
- Map three domain errors to HTTP status codes in a small helper.
- Scenario: when an interviewer asks you to fix code that swallows errors in a loop, how would you change it?
- Scenario: when a test must prove that a function wraps the original error, how would you write it?
Code Reading Questions
Read each program carefully and predict the output before you run it. Then explain the result in your own words.
package main
import (
"errors"
"fmt"
"os"
)
var ErrNotFound = errors.New("not found")
type QueryError struct {
Query string
Err error
}
func (e *QueryError) Error() string { return e.Query + ": " + e.Err.Error() }
func (e *QueryError) Unwrap() error { return e.Err }
func findUser(id int) error {
if id == 0 {
return &QueryError{Query: "user 0", Err: ErrNotFound}
}
return nil
}
func main() {
err := fmt.Errorf("load profile: %w", findUser(0))
fmt.Println(err)
fmt.Println(errors.Is(err, ErrNotFound))
var qe *QueryError
fmt.Println(errors.As(err, &qe), qe.Query)
plain := fmt.Errorf("load profile: %v", findUser(0))
fmt.Println(errors.Is(plain, ErrNotFound))
fmt.Println(errors.Is(err, os.ErrNotExist))
}
- What does each print line show, and why can errors.Is still find ErrNotFound two levels deep?
- Why does the check on plain return false, even though its message looks the same?
The second program mixes defer, recover, named results and errors.Join.
package main
import (
"errors"
"fmt"
)
func safeDivide(a, b int) (result int, err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("recovered: %v", r)
}
}()
defer fmt.Println("deferred print runs first")
result = a / b
return result, nil
}
func main() {
r, err := safeDivide(10, 2)
fmt.Println(r, err)
r, err = safeDivide(1, 0)
fmt.Println(r, err)
joined := errors.Join(errors.New("disk full"), errors.New("retry later"))
fmt.Println(joined)
}
- In what order do the lines print, and why does the second call return an error instead of crashing?
- How does errors.Join print its errors, and how would errors.Is treat the joined value?
Quick Revision Table for Go Errors
Use the table below as a final check before your interview. It compares the main tools for errors in Go.
| Tool | What it does | Use when |
|---|---|---|
| errors.New | Makes a simple error value | The message is fixed |
| fmt.Errorf with %w | Adds context and keeps the cause | You pass an error up |
| errors.Is | Finds a matching value in the chain | You check a sentinel error |
| errors.As | Finds a matching type in the chain | You need fields from the error |
| errors.Join | Combines several errors into one | Many checks can fail together |
| panic and recover | Stops or rescues a broken program | A bug, not a normal failure |
Also, many interviewers ask you to compare errors.Is and errors.As directly. The diagram below shows the difference side by side.

Official Resources
These official pages explain the rules behind these questions.
- Go blog: Working with errors in Go 1.13
- Package errors documentation
- Go blog: Defer, Panic, and Recover
- Effective Go: Errors
Quick Recap
- These Go error handling questions cover basics, custom errors, wrapping, design, panic and real services.
- An error is a value, so return it and handle it once.
- Wrap with %w to add context, then check the chain with errors.Is and errors.As.
- Keep sentinel errors few, because each one becomes part of your API.
- Panic only for real bugs, and recover only inside a deferred function.
- Log at the top of the stack and show users a safe message.
What’s Next?
By now, you have Go error handling questions for every part of errors and panics. Study the answers in your own notes, then check them against the Go interview topics study guide.
Next up: Go modules and packages interview questions (Part 10)


