How does error handling work in Go

Go handles errors by returning them as a second value that callers must explicitly check before proceeding.

Go handles errors by returning them as a second value from functions, which you must explicitly check with an if statement. This pattern forces the caller to decide how to handle the failure rather than using exceptions.

file, err := os.Open("filename.txt")
if err != nil {
    log.Fatal(err)
}
// Use file
file.Close()