Go2 Error Handling - Alternate Handler Concept

210 views
Skip to first unread message

Liam

unread,
Aug 29, 2018, 6:16:42 PM8/29/18
to golang-nuts
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

Vlad Didenko

unread,
Sep 2, 2018, 7:33:03 PM9/2/18
to golang-nuts
Some time ago, after going through a very similar design (really, even had the catch clause in there), I have arrived at a more generalized version of it. That contemplation (still available at https://didenko.github.io/grab/grab_worth_it_0.1.1.html ) was very much unaccepted here.

Well, I actually do not remember if it was posted here or in golang-dev.

Liam Breck

unread,
Sep 2, 2018, 7:46:08 PM9/2/18
to Vlad Didenko, golang-nuts
Well, that was then, this is now...

I'll just note that 10 of 30 feedback posts on the error handling draft feedback wiki have asked for named handlers. Can I add your link there?


--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/tW97ZxsCvdQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Vlad Didenko

unread,
Sep 2, 2018, 7:49:32 PM9/2/18
to golang-nuts
Absolutely, go ahead, thank you! I can add more "why" reasoning about "grab" design differences from "catch", but won't get to it until next weekend :(

Liam Breck

unread,
Sep 2, 2018, 11:21:46 PM9/2/18
to Vlad Didenko, golang-nuts
Posted your link to the feedback wiki, and to my design-revision draft, which will land on the issue tracker this week.


Reply all
Reply to author
Forward
0 new messages