rows, err := db.Query("SELECT * FROM users") if err != nil { log.Fatal(err) } defer rows.Close() for rows.Next() { var id int var name string var email string err := rows.Scan(&id, &name, &email) if err != nil { log.Fatal(err) } // process row data here } if err := rows.Err(); err != nil { log.Fatal(err) }In the above example, if the Rows.Next() function encounters an error while fetching rows, the loop will stop and the error will be logged. After the loop completes,Rows.Err() is called to see if there were any additional errors encountered. The package library used in this example is database/sql.