From dc4b669044fe7bd48ebf3426c65ead92e9e94f01 Mon Sep 17 00:00:00 2001 From: Anchor Date: Thu, 20 Nov 2014 09:47:47 -0800 Subject: [PATCH] Fix grammar and sentences for 11.1 intro --- en/eBook/11.1.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/en/eBook/11.1.md b/en/eBook/11.1.md index 87bb76c4..0d0ce912 100644 --- a/en/eBook/11.1.md +++ b/en/eBook/11.1.md @@ -1,17 +1,17 @@ # 11.1 Error handling -Go language major design criterion is : simple to understand , simple is the syntax similar to C is fairly simple to understand refers to any statement is obvious , does not contain any hidden things in the error-handling program design also implement this idea . We know that there is in the C language by returning -1 or NULL to indicate the kind of error message , but for users who do not view the API documentation , the return value never know exactly what does it mean , for example: return 0 is success or failure , and Go defines a type called the error to explicitly express errors. When in use, by the returned error variable nil comparison to determine whether the operation was successful. For example `os.Open` function opens the file will return a failure of the error variable is not nil +Go's major design considerations are rooted in the following ideas: a simple, clear, and concise syntax (similar to C), statements are explicit and don't contain hidden any hidden or unexpected things. Go's error handling scheme reflects all of these principles in the way that it's implemented. If you're familiar with the C language, you'll know that it's common to return -1 or NULL values to indicate that an error has occurred. However users who are not familiar with C's API will not know exactly what these return values mean. In C, it's not explicit whether a value of `0` indicates success of failure. On the other hand, Go explicitly defines a type called `error` for the sole purpose of expressing errors. Whenever a function returns, we check to see whether the error variable is `nil` or not to determine if the operation was successful. For example, the `os.Open` function fails, it will return a non-nil error variable. - func Open (name string) (file * File, err error) + func Open(name string) (file * File, err error) -Here's an example by calling `os.Open` open a file if an error occurs, it will call the `log.Fatal` to output an error message : +Here's an example of how we'd handle an error in `os.Open`. First, we attempt to open a file. When the function returns, we check to see whether it succeeded or not by comparing the error return value with nil, calling `log.Fatal` to output an error message if it's a non-nil value: f, err := os.Open("filename.ext") - if err != nil { - log.Fatal(err) - } + if err != nil { + log.Fatal(err) + } -Similar to the `os.Open` function, the standard package of all possible errors of the API will return an error variable to facilitate error handling, this section will detail error type design, and discuss how to develop Web applications to better handle error. +Similar to the `os.Open` function, the functions in Go's standard packages all return error variables to facilitate error handling. This section will go into detail about the design of error types and discuss how to properly handle errors in web applications. ## Error type