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
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/20230803014052.1f3d9d1b%40xmint.