The `func check(Condition bool) {}` applies to the block that follows.
Within this block, every statement that on its left-hand side has any
variable that is present in the "Condition" expression is supplemented
with an implicit check of `if Condition { goto catch }` form.

The 'catch:' label can be given explicit, or be assumed implicit at
last statement of the block.

// Condition is not restricted to `err != nil`. 
// Below snippet will `break` if x was < 4 after any of trX calls:

check(x < 4)
{
    x, y = trA(x, z)
    y, z = trB(x, y) // no x on lhs, no check
    x, y = trC(y, z)
    break
}


// `check` helps the most where many repetitive checks
// are to be performed in close proximity.

check(err != nil)
{
    ucred, err         := getUserCredentials(user)
    remote, err        := connectToApi(remoteUri)
    err, session, utok := remote.Auth(user, ucred)
    udata, err         := session.getCalendar(utok)

  catch:               // sad path, err != nil
    ucred.Clear()      // cleanup passwords
    remote.Close()     // do not leak sockets
    return nil, 0,     // dress before leaving
      fmt.Errorf("Can not get user's Calendar because of: %v", err)
}
// happy path


The proposal is at https://github.com/golang/go/issues/32968

Please leave a comment for your possible thumb-down, as
I would like to know about flaws I do not see as the author.

Thank you,

-- 
Wojciech S. Czarnecki
 << ^oo^ >> OHIR-RIPE

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

Reply via email to