← Go Programming learning pathGo Programming · Module 7 of 10
Error handling
Handle errors explicitly as values.
📖 Key ideas
- Functions return error as the last value.
- Check: if err != nil { return err }.
- Create errors: errors.New("msg") or fmt.Errorf("...: %w", err).
- errors.Is and errors.As inspect wrapped errors.
- panic is for unrecoverable situations; recover can catch it.
💡 Real-life example: Go errors are receipts handed back with every delivery: always check if something went wrong.
errorBuilt-in interface for errors
fmt.Errorf %wWraps an error
errors.IsChecks for a specific error
panicStops normal execution