Skip to content

Commit fcd8845

Browse files
committed
update files 2019年 5月17日 星期五 17时53分47秒 CST
1 parent 864918b commit fcd8845

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

errors.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ title: Handling Errors
66
Almost all operations with `database/sql` types return an error as the last
77
value. You should always check these errors, never ignore them.
88

9+
几乎所有使用 `database/sql` 类型的操作都会返回错误作为最后一个值。您应该始终检查这些错误,不要忽略它们。
10+
911
There are a few places where error behavior is special-case, or there's
1012
something additional you might need to know.
1113

14+
在某些地方,错误行为是特殊情况,或者您可能需要了解其他一些内容。
15+
1216
Errors From Iterating Resultsets
1317
================================
1418

@@ -30,13 +34,17 @@ need to check whether the loop terminated normally or not. An abnormal
3034
termination automatically calls `rows.Close()`, although it's harmless to call it
3135
multiple times.
3236

37+
`rows.Err()` 中的错误可能是 `rows.Next()` 循环中的各种错误的结果。除了正常完成循环之外,循环可能由于某种原因而退出,因此您始终需要检查循环是否正常终止。异常终止会自动调用 `rows.Close()` ,尽管多次调用它是无害的。
38+
3339
Errors From Closing Resultsets
3440
==============================
3541

3642
You should always explicitly close a `sql.Rows` if you exit the loop
3743
prematurely, as previously mentioned. It's auto-closed if the loop exits
3844
normally or through an error, but you might mistakenly do this:
3945

46+
如前所述,如果过早地退出循环,则应始终显式关闭sql.Rows。如果循环正常退出或通过错误退出,它会自动关闭,但您可能会错误地执行此操作:
47+
4048
<pre class="prettyprint lang-go">
4149
for rows.Next() {
4250
// ...

0 commit comments

Comments
 (0)