Go by Example - Errors
Go by Example
Go is an open source programming language designed for building simple, fast, and reliable software.
Go by Example is a hands-on introduction to Go using annotated example programs. Check out the first example or browse the full list below.
Go by Example: Errors
golang中通过显式、单独的返回值来标识错误是一种常用的语言习惯。这与java和ruby等语言中使用的异常或C语言中有时使用重载单个返回值/错误是不同的。golang的这种处理方式很容易获取方法中返回的错误并且与其他没有返回错误的情况有相同的语句结构。
1 | package main |
1 | $ go run errors.go |