Re the Go2 Error Handling proposal
I have posted this feedback
Which contains an alternate handler concept. Please let me know if you think this merits its own
github.com/golang issue.
A flag identifier indicates errors of various types. This also allows chaining of handlers with the same flag name. There are options for the #flag syntax, e.g. flag!, $flag, @flag, etc.
func f() {
v, #ret := returnIfError() // #ret can be any type; any non-zero value for it triggers its catch
v, #fat := fatalIfError() // #ret, etc are (probably) not local variables
v, #wrt := writeOnError()
if v != nice { // new scope
#fat = MyError{msg:"!nice", ...}
catch fat error { debug.PrintStack() } // no return/exit; chained with next catch fat
}
#packageFlag = anotherError() // invokes package-level handler
catch ret error { return ret } // if type is error, type name could be optional
catch fat error { log.Fatal(fat) }
catch wrt error { con.Write(...); return nil } // return/exit required in last handler on chain
}
catch packageFlag error { ... } // package-level handler; packageFlag is not a package variable