File tree Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -6,9 +6,13 @@ title: Handling Errors
6
6
Almost all operations with ` database/sql ` types return an error as the last
7
7
value. You should always check these errors, never ignore them.
8
8
9
+ 几乎所有使用 ` database/sql ` 类型的操作都会返回错误作为最后一个值。您应该始终检查这些错误,不要忽略它们。
10
+
9
11
There are a few places where error behavior is special-case, or there's
10
12
something additional you might need to know.
11
13
14
+ 在某些地方,错误行为是特殊情况,或者您可能需要了解其他一些内容。
15
+
12
16
Errors From Iterating Resultsets
13
17
================================
14
18
@@ -30,13 +34,17 @@ need to check whether the loop terminated normally or not. An abnormal
30
34
termination automatically calls ` rows.Close() ` , although it's harmless to call it
31
35
multiple times.
32
36
37
+ ` rows.Err() ` 中的错误可能是 ` rows.Next() ` 循环中的各种错误的结果。除了正常完成循环之外,循环可能由于某种原因而退出,因此您始终需要检查循环是否正常终止。异常终止会自动调用 ` rows.Close() ` ,尽管多次调用它是无害的。
38
+
33
39
Errors From Closing Resultsets
34
40
==============================
35
41
36
42
You should always explicitly close a ` sql.Rows ` if you exit the loop
37
43
prematurely, as previously mentioned. It's auto-closed if the loop exits
38
44
normally or through an error, but you might mistakenly do this:
39
45
46
+ 如前所述,如果过早地退出循环,则应始终显式关闭sql.Rows。如果循环正常退出或通过错误退出,它会自动关闭,但您可能会错误地执行此操作:
47
+
40
48
<pre class =" prettyprint lang-go " >
41
49
for rows.Next() {
42
50
// ...
You can’t perform that action at this time.
0 commit comments