The double caret statement aka "erret" or "bat return") ad-hoc specification.
"^^" (erret) statement specify the conditional execution of a following terminating statement, the condition being a built-in check whether any of the function F named result parameter of interface type _error_ is not nil.
ErretStmt = "^^" ( ReturnStmt | Block ) .
If ErretStmt is followed by a block, this block must itself be a terminating statement too.
There is an implicit semicolon added to the leading caret ie. ;^^
In plain words:
When code execution reaches the double caret statement all named result parameters of error type
are evaluated for being nil. If any of those is not nil a terminating statement is executed.
Otherwise control flow passes to the statement next to it.
func ParseFile(filename string) e error {
fh, e := os.Open(filename) ^^ return
defer fh.Close()
x, e := tryparse(fh) ^^ {
logSmth(e)
return
}
// ...
return
}
Reference thread:
https://groups.google.com/d/msgid/golang-nuts/18e49891-9012-433d-89ce-3dfcc0625cedn%40googlegroups.com
P.S. That is for YetAnotherOfThousandOfGoErrorHandlingIdeas being archived ;)
--
Wojciech S. Czarnecki
<< ^oo^ >> OHIR-RIPE