2
0
mirror of https://github.com/chubin/cheat.sheets synced 2024-11-19 03:25:44 +00:00
cheat.sheets/sheets/_go/Errors

20 lines
440 B
Plaintext
Raw Normal View History

2017-05-28 21:17:32 +00:00
// 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
}
}