Here's a short example comparing existing error handling, the check proposal, and the experimental try proposal
https://gist.github.com/kyleconroy/e48c83425349f2d3954d4e764...
https://gist.github.com/kyleconroy/e48c83425349f2d3954d4e764...
I'm not a fan of the verbosity at present either, but seems like the check/handle syntax is less direct and the try()/defer func syntax is less flexible.
handle err {
w.Close()
os.Remove(dst) // (only if a check fails)
}
the error returned from w.Close() is not handled.On the other hand,
w := try(s.Create(dst))
try(io.Copy(w, r))
try(w.Close())
return nil
this code has the problem where if there were an error in the `Copy`, the file descriptor would be leaked.So, yes, one of the examples is wrong.