Description
It looks like #32437 is the current most popular error handling proposal. This proposal wishes to introduce a try()
statement that returns the default values of all return variables if a value other than nil
is returned as the last value from a function. In normal function, the try()
statement returns all values that are not the final error value.
How about instead of wrapping things in parentheses all over the place, we directly put a special key (like !!
or anything else) into the place where the error is returned? That's shorter and all other behaviour is the same. Also, you don't have invisible returns here, or require the error to be the last thing returned.
This also discourages changing try statements together which keeps code more readable.
func Foo() (err error) {
file, !! = os.Open("file1.txt")
defer file.Close()
parsed, !! = parseFile(file)
fmt.Printf("%s", parsed)
return nil
}