← All Exercises
Go Error Handling
basicgo
Background
Go uses explicit error returns instead of exceptions, requiring consistent error checking throughout code.
Problem
Write a Go function that safely divides two integers, returning an error if the divisor is zero.
Input
Two integers: numerator and denominator.
Output
The division result and nil error, or 0 and an error for division by zero.
Sample tests
Sample 1
Input: 10, 2
Expected: 5, nil
Your solution
Learning objective
Learn Go error return convention, error creation with errors.New, and the multiple return value pattern.