Goworkinggo1
Error handling
Errors are values you return, check, and inspect — not exceptions you throw.
Go models failure with a returned error value; fmt.Errorf("...: %w", err) wraps it, and errors.Is/errors.As inspect the chain.
Return an error, check it
Gointro0ms
half of 10 is 5error: cannot halve an odd number
Reference · output compiled offline, not runnable in-browser
The even call returns a nil error so the else branch prints the value, while the odd call returns a non-nil error that the caller inspects instead of the (zeroed) first return. This is the core if err != nil flow: check the error before trusting the other results.