Quiz · Errors · lesson 3 of 11Quiz — creating an errorHow do you create a new error value in Go, with or without context?[A]Build errors only by defining a custom struct and a String() method on it; the standard library offers no constructor for them at all. To add context you concatenate strings by hand, since fmt.Errorf formats plain text but cannot return an error. There is no wrapping mechanism, so the original cause is always lost the moment you build a new message around it.[B]Create an error by calling panic("message"): the call stops the function and hands the message back to the caller as an error value. errors.New exists only inside test code, and fmt.Errorf only prints the text without returning anything. The %w verb is a formatting alias for %v and has nothing to do with wrapping or unwrapping a cause.[C]Use errors.New("message") for a fixed, static message, or fmt.Errorf("context: %v", x) when you need to format details into the text. Both return a value satisfying the error interface. fmt.Errorf with the %w verb additionally wraps an existing error, so callers can later find it with errors.Is to check the original cause.[D]Use errors.New("message") for a static text, or fmt.Errorf("context: %v", x) to format details in. Both yield a value of the error interface type. Passing %v to fmt.Errorf also wraps an inner error, letting callers later find it with errors.Is to look at the underlying root cause of the failure.Subscribe to take the courseThe course is free. Sign in with Telegram and subscribe to the channel to open every lesson.Continue with TelegramSign in another way← Backerrors.New and fmt.ErrorfNext →Checking if err != nil