mirror of
https://github.com/chubin/cheat.sheets
synced 2024-11-15 06:12:59 +00:00
20 lines
440 B
Plaintext
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
|
|
}
|
|
}
|