===== Error Handling ===== ==== What is it? ==== In Go, **errors** are values returned from functions. The common pattern is: return `(result, error)` and check `if err != nil`. ==== What is it used for? ==== * Report failures without exceptions. * Keep control flow explicit. * Add context to failures (wrapping) and handle them appropriately. ==== Core topics ==== * [[go:errors:error_interface|error interface]] * [[go:errors:custom_errors|Custom errors]] * [[go:errors:sentinel_errors|Sentinel errors]] * [[go:errors:error_wrapping|Error wrapping (%w)]] * [[go:errors:errors_is_as|errors.Is / errors.As]] * [[go:errors:panic_vs_error|panic vs error]] * [[go:errors:defer_cleanup|defer for cleanup]] ==== Hard words (English) ==== * **explicit** /ɪkˈsplɪsɪt/: tường minh * **failure** /ˈfeɪljər/: lỗi/thất bại * **context** /ˈkɑːntekst/: ngữ cảnh