Challenge 2 — Solution Task: Define a custom error type RangeError with fields Min and Max ints, and an Error() string method describing the valid range. Write a function checkAge(age int) error returning a *RangeError if age is outside 0-120. Use errors.As to extract it and print Min/Max. package main import ( "errors" "fmt" ) type RangeError struct { Min int Max int } func (e *RangeError) Error() string { return fmt.Sprintf("value must be between %d and %d", e.Min, e.Max) } func checkAge(age int) error { if age < 0 || age > 120 { return &RangeError{Min: 0, Max: 120} } return nil } func main() { err := checkAge(150) var rangeErr *RangeError if errors.As(err, &rangeErr) { fmt.Println("Out of range. Min:", rangeErr.Min, "Max:", rangeErr.Max) } } Expected output: Out of range. Min: 0 Max: 120 Notes: - *RangeError satisfies Go's built-in error interface purely because it has an Error() string method — there's no separate declaration needed connecting it to error. - errors.As(err, &rangeErr) both checks the type AND assigns err into rangeErr if it matches, which is what makes rangeErr.Min and rangeErr.Max accessible afterward — a plain error variable alone could never expose those fields. - var rangeErr *RangeError starts as nil; errors.As only succeeds (returns true) if err is genuinely a *RangeError somewhere in its chain.