With the current proposal 
<https://go.googlesource.com/proposal/+/master/design/go2draft-error-handling-overview.md>
 
we will need to introduce two new definitions: the handler block and check 
keyword.
One thing, I still not sure how "check" will handle the repetition of other 
failure check form, for example the one that using boolean like checking if 
an key exist in map or type assertion successful.

How about a new keyword but using normal function as condition for return? 
Example:

func errorWrap(src, dst string, err error) (wrappedErr error, shouldReturn 
bool) {
if err != nil {
return fmt.Errorf("copy %s %s: %v", src, dst, err), true
}

return nil, false
}

func CopyFile(src, dst string) error {
r, err := os.Open(src)
checkReturn errorWrap(src, dst, err)
defer r.Close()

w, err := os.Create(dst)
checkReturn errorWrap(src, dst, err)

handingError := func(err error) (error, bool) {
if err == nil {
return nil, false
}

w.Close()
os.Remove(dst)
return errorWrap(src, dst, err)
} 
_, err = io.Copy(w, r)
checkReturn handingError(err)
checkReturn handingError(w.Close())
}


"checkReturn" function returns values must match the caller return values 
with an additional boolean check for caller.
The return values that match the caller then will be use as return values 
for the caller.
In the example, CopyFile return 1 error, so the "checkReturn" function must 
return (error, bool).
"checkReturn" will act like "return" if the final boolean value is true.

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to