Skip to content
This repository has been archived by the owner on May 24, 2023. It is now read-only.

Update retrieving.md: Make the warning about runtime panic when closing rows more explicit #106

Open
wants to merge 1 commit into
base: gh-pages
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions retrieving.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ A couple parts of this are easy to get wrong, and can have bad consequences.
* `rows.Close()` is a harmless no-op if it's already closed, so you can call
it multiple times. Notice, however, that we check the error first, and only
call `rows.Close()` if there isn't an error, in order to avoid a runtime panic.
For example, if `rows` is `nil`, `defer rows.Close()` will cause a nil pointer dereference panic after the function exits.
* You should **always `defer rows.Close()`**, even if you also call `rows.Close()`
explicitly at the end of the loop, which isn't a bad idea.
* Don't `defer` within a loop. A deferred statement doesn't get executed until
Expand Down