Answer the question
In order to leave comments, you need to log in
How to use check/handle in Golang?
I tried to write handlers for the check statement in the Go 2 Error Handling article , but, for example, this code, taken from the article, does not compile:
func printSum(a, b string) error {
handle err { return err }
x := check strconv.Atoi(a)
y := check strconv.Atoi(b)
fmt.Println("result:", x + y)
return nil
}
check-handle/main.go:13:12: syntax error: unexpected err at end of statement
check-handle/main.go:14:5: syntax error: non-declaration statement outside function body
rawSubStart, err := parseTime(rawSub.Start)
if err != nil {
return err
}
rawSubEnd, err := parseTime(rawSub.End)
if err != nil {
return err
}
Answer the question
In order to leave comments, you need to log in
Do you have version 2?
Hint: version 2 doesn't exist :) and the article describes ideas that might be added to Go someday in a future that hasn't happened yet.
in the article it says:
Design drafts are not even proposals (proposals) with which any change in the library, tooling or the Go language begins. This is a starting point for design discussion, proposed by the Go team after years of working on these issues. Everything that is described in drafts will most likely be changed, and, in the best scenario, will become reality only after a few releases (I give ~2 years).
If it’s not difficult, please advise how best to handle errors, since I have a copy-paste from the error handler in my code, for example:
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question