-
Notifications
You must be signed in to change notification settings - Fork 17.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proposal: Go 2: catch error handler #43777
Comments
Please fill out https://github.com/golang/proposal/blob/master/go2-language-changes.md when proposing language changes |
Some form of try/catch has been proposed many times in the past and none of these proposals have been accepted: https://github.com/golang/go/issues?q=is%3Aissue+is%3Aclosed+%22try%2Fcatch%22+label%3Aerror-handling+ What makes this proposal any different? |
no returning error from function, internal mechanisms for observe, only throw operator which makes error call and catch the handler. something very similar to other languages semantically. one more thing to language core developers to notice, although such engineers better know |
What is the difference between What is the difference between |
as far as I know, panic should be used as limited as possible, especially in libraries
the function returns only useful payload, no error tails, code become clearer so what I mean here, this is essentially a try-catch-finally behavior: |
What happens if there is a It's fine to call I agree that calls to |
I think if no or
|
Based on the discussion above, and the lack of support in the emoji voting, this is a likely decline. Leaving open for four weeks for final comments. |
Would you consider yourself a novice, intermediate, or experienced Go programmer?
novice
What other languages do you have experience with?
JS, C#, Dart
Would this change make Go easier or harder to learn, and why?
I believe easier
Has this idea, or one like it, been proposed before?
some similar ideas of course were, but this different
If so, how does this proposal differ?
Who does this proposal help, and why?
help to handle errors in a more convenient way, increase performance by using less memory
What is the proposed change?
error handling
Please describe as precisely as possible the change to the language.
adding throw catch functionality
catch works like defer but only in case when some function in scope throws an exception
the scope of the catch block is function scope
it could be a set of catch blocks
catch block runs only if the code in func scope throws an error
What would change in the language spec?
adding throw, catch keywords
Please also describe the change informally, as in a class teaching Go.
if the function throws an error then the next catch block can handle it
Is this change backward compatible?
no, the old way should not conflict with this approach
Breaking the Go 1 compatibility guarantee is a large cost and requires a large benefit.
do not break
Show example code before and after the change.
before:
after:
or:
or:
What is the cost of this proposal? (Every language change has a cost).
benefits of having this approach :
How many tools (such as vet, gopls, gofmt, goimports, etc.) would be affected?
none
What is the compile time cost?
possible internal optimization as a new mechanism
What is the run time cost?
possible internal optimization as a new mechanism
Can you describe a possible implementation?
sure
Do you have a prototype? (This is not required.)
code above
How would the language spec change?
a bit
Orthogonality: how does this change interact or overlap with existing features?
does not conflict
Is the goal of this change a performance improvement?
performance improvements also
If so, what quantifiable improvement should we expect?
an application could use less memory
How would we measure it?
depends on implementation
Does this affect error handling?
yes
If so, how does this differ from previous error handling proposals?
because not necessary to create a new variable err every time, performance increases
Is this about generics?
nope
If so, how does this differ from the current design draft and the previous generics proposals?
don't know
The text was updated successfully, but these errors were encountered: