File tree Expand file tree Collapse file tree 2 files changed +4
-4
lines changed Expand file tree Collapse file tree 2 files changed +4
-4
lines changed Original file line number Diff line number Diff line change @@ -72,14 +72,14 @@ Offset字段在调用Error的时候不会被打印,但是我们可以通过类
72
72
return err
73
73
}
74
74
75
- 需要注意的是,函数返回自定义错误时,返回值也应设置为error类型 ,而非自定义错误类型,也不应预声明自定义错误类型的变量 。例如:
75
+ 需要注意的是,函数返回自定义错误时,返回值推荐设置为error类型 ,而非自定义错误类型,特别需要注意的是不应预声明自定义错误类型的变量 。例如:
76
76
77
77
func Decode() *SyntaxError { // 错误,将可能导致上层调用者err!=nil的判断永远为true。
78
78
var err *SyntaxError // 预声明错误变量
79
79
if 出错条件 {
80
80
err = &SyntaxError{}
81
81
}
82
- return err // 错误,虽然err变量等于nil,但仍可能导致上层调用者err!=nil的判断为true
82
+ return err // 错误,err永远等于非nil,导致上层调用者err!=nil的判断始终为true
83
83
}
84
84
85
85
原因见 http://golang.org/doc/faq#nil_error
Original file line number Diff line number Diff line change @@ -260,5 +260,5 @@ ControllerRegistor对外的接口函数有
260
260
261
261
## links
262
262
* [ 目录] ( < preface.md > )
263
- * 上一章: [ 数据库设计 ] ( < 13.2 .md > )
264
- * 下一节: [ controller设计] ( < 13.4 .md > )
263
+ * 上一章: [ 项目规划 ] ( < 13.1 .md > )
264
+ * 下一节: [ controller设计] ( < 13.3 .md > )
You can’t perform that action at this time.
0 commit comments