2
0
mirror of https://github.com/chubin/cheat.sheets synced 2024-11-01 21:40:24 +00:00
cheat.sheets/sheets/_go/Errors
2017-05-28 21:17:32 +00:00

20 lines
440 B
Plaintext

// There is no exception handling.
// Functions that might produce an error just declare an additional return value of type `Error`.
// This is the `Error` interface:
type error interface {
Error() string
}
//
// A function that might return an error:
func doStuff() (int, error) {
}
//
func main() {
result, error := doStuff()
if (error != nil) {
// handle error
} else {
// all is good, use result
}
}