yoklainterview sim

Backend Go Errors Interview Questions

75 verified Backend Go Errors interview questions — solve with answers, learn from explanations, test yourself in a real simulation.

Try the real simulation →

Sample questions

Go ErrorsDifficulty 1
In Go, what is the error type?
  • aA built-in exception class thrown automatically by the runtime
  • bAn interface with one method: Error() string
  • cA struct with Code and Message fields defined in package errors
  • dA reserved keyword used only inside panic statements
Explanation:error is defined as type error interface { Error() string }. Any type implementing that method satisfies the interface. Go has no built-in exception mechanism for ordinary error handling; errors are ordinary values.
Go ErrorsDifficulty 1
n, err := strconv.Atoi("abc")
fmt.Println(n * 2)
if err != nil {
    fmt.Println("error:", err)
}

What does this program print?
  • a"0", then an error message
  • bThe program crashes before printing anything
  • cIt fails to compile
  • dNothing is printed at all
Explanation:strconv.Atoi returns (0, err) on failure, so n is 0. n*2 prints 0 without panicking, and the error check afterward prints the error too. Using n before checking err isn't a compile error or a crash here — it's a logic bug because n is meaningless once err != nil.
Go ErrorsDifficulty 1
What's the key practical difference between errors.New("msg") and fmt.Errorf("msg")?
  • aerrors.New is deprecated and shouldn't be used anymore
  • bfmt.Errorf can only be called from inside package fmt
  • cerrors.New allocates on the heap while fmt.Errorf never does
  • dfmt.Errorf supports %w wrapping; errors.New does not
Explanation:fmt.Errorf formats like Printf; passing it %w with an error argument sets that error as the wrapped target so errors.Is/errors.As can find it later. errors.New just produces a fixed string with no formatting or wrapping ability.
Go ErrorsDifficulty 2
var ErrNotFound = errors.New("not found")

func find() error {
    return fmt.Errorf("lookup failed: %v", ErrNotFound)
}

func main() {
    fmt.Println(errors.Is(find(), ErrNotFound))
}

What does this print?
  • atrue
  • bfalse
  • cIt fails to compile
  • d"not found"
Explanation:%v only formats ErrNotFound's text into the new error's message; it does not set an Unwrap chain — only %w does that. Since the returned error has no wrapped target, errors.Is can't find ErrNotFound anywhere in its chain and returns false.
Go ErrorsDifficulty 2
var ErrClosed = errors.New("connection closed")

func send() error {
    return fmt.Errorf("send failed: %w", ErrClosed)
}

func main() {
    fmt.Println(errors.Is(send(), ErrClosed))
}

What does this print?
  • atrue
  • bfalse
  • cIt fails to compile
  • d"connection closed"
Explanation:%w sets send()'s returned error to wrap ErrClosed, so errors.Is walks the chain, finds ErrClosed, and returns true.
Go ErrorsDifficulty 2
type ValidationError struct {
    Field string
}

func (e *ValidationError) Error() string {
    return "invalid field: " + e.Field
}

func validate() error {
    return fmt.Errorf("request rejected: %w", &ValidationError{Field: "email"})
}

func main() {
    var ve *ValidationError
    if errors.As(validate(), &ve) {
        fmt.Println(ve.Field)
    }
}

What does this print?
  • aIt fails to compile
  • bNothing is printed
  • c"email"
  • d"invalid field: email"
Explanation:errors.As walks the chain, finds the *ValidationError, and assigns it to ve. ve.Field is then just the struct field "email", not the full Error() string.

Test yourself against the 3300-question Backend bank.

Start interview