Go can already pass/pipe the result of a function, which returns multiple 
values, to another function, which accepts the same values as arguments. A 
similar mechanism can be used for handling errors, by passing/pipe them to 
a special construct.

Now, assume we have a function named funcCtx:

func funcCtx() (res int, err error) { 
    // ...
}

Having that, these does not look that ugly:

func funcCtx() (res int, err error) {
    res, return() = action()
    // or
    res, panic() = action()
}

Those statements will have an effect, only if the returned value is not 
nil. For performing some actions, before the actual return or panic:

res, return({ log.Println(err) }) = action()

There is this restriction, that the function that contains this block, 
funcCtx, has to return named return values - for both handling the zero 
values and having a one to one mapping between its return values and those 
of action function.

Also for having a name, err in this case, that makes it clear, which 
variable we are talking about.

In the proposal 
<https://go.googlesource.com/proposal/+/master/design/go2draft-error-handling-overview.md>,
 
it's not clear where the err variable comes from (what if there are three 
return values?)

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/64b29c6d-1da1-4f65-a8bf-c1ca01cd31f0n%40googlegroups.com.

Reply via email to