You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: en/11.1.md
+3-3
Original file line number
Diff line number
Diff line change
@@ -76,7 +76,7 @@ The error's `Offset` field will not be printed at runtime when syntax errors occ
76
76
return err
77
77
}
78
78
79
-
It should be noted that when the function returns a custom error, the return value is set to the recommend type of error rather than a custom error type. Be careful not to pre-declare variables of custom error types. For example:
79
+
It should be noted that when the function returns a custom error, the return value is set to the recommended type of error rather than a custom error type. Be careful not to pre-declare variables of custom error types. For example:
80
80
81
81
func Decode() *SyntaxError {
82
82
// error, which may lead to the caller's err != nil comparison to always be true.
@@ -112,7 +112,7 @@ Using type assertion, we can check whether or not our error is of type net.Error
112
112
113
113
## Error handling
114
114
115
-
Go handles errors and checks the return values of functions in a C-like fashion, which is different than what most of the other major languages do. This makes the code more explicit and predictable, but also more verbose. To reduce the redundancy of our error-handling code, we can use abstract error handling functions that allow us to implement similar error handling behaviour:
115
+
Go handles errors and checks the return values of functions in a C-like fashion, which is different to how most of the other major languages do. This makes the code more explicit and predictable, but also more verbose. To reduce the redundancy of our error-handling code, we can use abstract error handling functions that allow us to implement similar error handling behaviour:
116
116
117
117
func init() {
118
118
http.HandleFunc("/view", viewRecord)
@@ -131,7 +131,7 @@ Go handles errors and checks the return values of functions in a C-like fashion,
131
131
}
132
132
}
133
133
134
-
The above example demonstrate access to data and template call has detected error when an error occurs , call a unified handler http.Error, returns a 500 error code to the client , and display the corresponding error data. But when more and more HandleFunc join, so error-handling logic code will be more and more, in fact, we can customize the router to reduce code (refer to realize the idea of the third chapter of HTTP Detailed).
134
+
The above example demonstrate how the data access and template call has detected an error. When an error occurs , a call to unified handler http.Error, returns a 500 error code to the client , and displays the corresponding error data. But when more and more HandleFunc calls are made, so error-handling logic code will increase. We can customize the router to reduce code (refer to the third chapter of HTTP for more detail).
135
135
136
136
type appHandler func(http.ResponseWriter, *http.Request) error
0 commit comments