-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors03.go
More file actions
33 lines (25 loc) · 875 Bytes
/
errors03.go
File metadata and controls
33 lines (25 loc) · 875 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/* Alta3 Research | RZFeeser
Errors - Returning errors from functions */
package main
import (
"errors"
"fmt"
)
// notice that error is the type being returned
// the universal block describes this as being a basic type
// accessible to all programs (along with int, string, true, false, etc.)
func endit() error {
// this function always returns an error
return errors.New("we don't have the power")
}
func main() {
// call the function endit that returns na error
err := endit()
// we will always find an error (thats all that endit() can produce)
if err != nil { // this paradigm replaces try/catch from other languages
fmt.Println("We detected and error:", err)
return // return from main()
}
// this will only run if no error occurs
fmt.Println("Release the hounds!")
}