A counter proposal to the try proposal - catch

249 views
Skip to first unread message

Nate Finch

unread,
Jun 27, 2019, 2:44:23 PM6/27/19
to golang-nuts
I really don't like the try proposal, because I think it hurts readabiity of the code.  But I think the fix is not too hard, so I made a counter proposal, catch:


Catch works just like try, except it has to be a statement and has to be passed an error explicitly, rather than returning arguments to the left hand side.  This make the conversion of old code to new code look a lot more like normal go code.


Liam

unread,
Jun 30, 2019, 12:04:59 PM6/30/19
to golang-nuts
If you really care to "catch" errors, you want this:

If all you need is to allocate a line to check an error and take an action, you want this:

But it's all moot. the Go team has told us we must prove that try is inadequate for existing Go projects, and altho that can be proved, it won't be clear for a couple years until use of Error Values propagates.

Robert Engels

unread,
Jun 30, 2019, 1:03:49 PM6/30/19
to Liam, golang-nuts
I think both of the proposals are fine, but they suffer from the “lack of completeness”. In that, they improve things, but don’t go far enough so the incremental benefit is not high enough. A key component of exceptions is the concept of ‘throws’ which is both self documenting, and requires handling, which enables flow analysis (manual and automated). These proposals don’t supply this functionality. They also don’t cover automatic stack capture, which is essential in diagnosing problems in large, complex systems. 
--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/68e3407a-57cc-42f2-8819-7c0369f5ca4b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

mh cbon

unread,
Jul 3, 2019, 9:23:09 AM7/3/19
to golang-nuts
but exceptions are shit. even the typed catch/final statements are a workaround.


On Sunday, June 30, 2019 at 7:03:49 PM UTC+2, Robert Engels wrote:
I think both of the proposals are fine, but they suffer from the “lack of completeness”. In that, they improve things, but don’t go far enough so the incremental benefit is not high enough. A key component of exceptions is the concept of ‘throws’ which is both self documenting, and requires handling, which enables flow analysis (manual and automated). These proposals don’t supply this functionality. They also don’t cover automatic stack capture, which is essential in diagnosing problems in large, complex systems. 

On Jun 30, 2019, at 11:04 AM, Liam <networ...@gmail.com> wrote:

If you really care to "catch" errors, you want this:

If all you need is to allocate a line to check an error and take an action, you want this:

But it's all moot. the Go team has told us we must prove that try is inadequate for existing Go projects, and altho that can be proved, it won't be clear for a couple years until use of Error Values propagates.

On Thursday, June 27, 2019 at 11:44:23 AM UTC-7, Nate Finch wrote:
I really don't like the try proposal, because I think it hurts readabiity of the code.  But I think the fix is not too hard, so I made a counter proposal, catch:


Catch works just like try, except it has to be a statement and has to be passed an error explicitly, rather than returning arguments to the left hand side.  This make the conversion of old code to new code look a lot more like normal go code.


--
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 golan...@googlegroups.com.

Robert Engels

unread,
Jul 3, 2019, 10:14:19 AM7/3/19
to mh cbon, golang-nuts
The two posts I made regarding the errors as values blog clearly demonstrates the significant problems with the current approach. 
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/e706cd96-1a07-4d02-a92c-a13538e17388%40googlegroups.com.

mh cbon

unread,
Jul 4, 2019, 4:41:02 PM7/4/19
to golang-nuts
sorry, i cant find your posts by asking my friend google, not reading your signature.

would you be kinder than me to post their urls so i can figure out how you consider few cases ?
thank you.
Reply all
Reply to author
Forward
0 new messages