Answers for "go error handling"

Go
2

golang create error

// simple string-based error
err1 := errors.New("math: square root of negative number")
Posted by: Guest on August-13-2020
0

go error handling

func doStuff() (int, error) {
}

func main() {
    result, err := doStuff()
    if err != nil {
        // handle error
    } else {
        // all is good, use result
    }
}
Posted by: Guest on January-12-2021

Browse Popular Code Answers by Language