From 23e2abf7ca94c12a35bd986b1fd7de7a736103e8 Mon Sep 17 00:00:00 2001 From: LazyWolf Lin Date: Fri, 25 Jan 2019 13:31:04 +0800 Subject: [PATCH] Translating An Introduction to Go. --- .../tech/20181224 An Introduction to Go.md | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/translated/tech/20181224 An Introduction to Go.md b/translated/tech/20181224 An Introduction to Go.md index a63bd98003..0c2758fe2f 100644 --- a/translated/tech/20181224 An Introduction to Go.md +++ b/translated/tech/20181224 An Introduction to Go.md @@ -192,21 +192,21 @@ func myFunc(someFile io.ReadCloser) { ### 错误处理 -Go does not provide exceptions or structured error handling. Instead, it handles errors by returning them in a second or later return value: +Go 没有提供异常类或者结构化的错误处理。然而,它通过第二个及后续的返回值来返回错误从而处理错误: ``` func Read(p []byte) (n int, err error) -// Built-in type: +// 内建类型: type error interface { Error() string } ``` -Errors have to be checked in the code, or can be assigned to `_`: +必须在代码中检查错误或者赋值给 `_`: ``` -n0, _ := Read(Buffer) // ignore error +n0, _ := Read(Buffer) // 忽略错误 n, err := Read(buffer) if err != nil { return err @@ -217,15 +217,15 @@ There are two functions to quickly unwind and recover the call stack, though: `p ``` func Function() (err error) { - defer func() { - s := recover() - switch s := s.(type) { // type switch - case error: - err = s // s has type error now - default: - panic(s) - } - } + defer func() { + s := recover() + switch s := s.(type) { // type switch + case error: + err = s // s has type error now + default: + panic(s) + } + } } ```