-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: improve error handling syntax #36390
Comments
Thank you for your proposal I find it very interesting, although I don't like the idea of placing signs after the variables, it can be a bit confusing and too many new concepts that seem complicated to reuse. |
How would you handle with more than one type of errors, a single line of code can be challenging?
|
Personally I don't think we need to make it easier to panic on errors. As I understand this proposal that can be implemented easily enough using the The use of In your example patient, ok! := dictPatient["boob"] =>
fmt.Errorf("Patient id %s not found %w", id, err) the code uses a variable If we use For that matter you don't really spell out what values the function returns if we use |
@proyb6 this syntax can handle multiple variable just fine as the symbol "?" or "!" can only be used with the last variable in assign or define statement. It similar to other proposal as it enforce the function to have error type as the last value in the return signature. The syntax does not support the case where function return more than 1 error but technically, we can support such as case by dropping a few rules such as:
However this syntax does not allow explicit return statement, so it would be impossible for compiler to generate or transform the code without restriction. So I don't see this syntax would support such as case. |
Just clarify, I did not mention clearly about a statement after " |
Go doesn't have lambda expressions (other than function literals which is clearly not what you mean). So I think you need to clarify what can follow |
@ianlancetaylor there are 2 type that valid after "
|
Close this proposal as not many in the community interested in such as syntax change. |
Salute to everyone here, for the pass few weeks, I've read through all error handling proposal and I know most of them is likely to be rejected at the moment however I would like to put my idea here to help shape up the future if possible.
This proposal utilize 2 new symbols
?
and=>
with an existing symbol!
to improve error handling and various part of the language.!
" symbol if we want to panic application?
" symbol if we want to return from the function=>
" symbol to provide custom error or wrapped errorAcceptant Syntax
!
and?
is allow to use with the last variable in assign or define statement only.bool
or anerror
type where bool would only work withmap
,channel
andcasting
err? := firstPatient()
patient, ok! := dictPatient["boob"]
number, ok? := it.(int)
patient, ok? := <- patientQueue
?
is allow to use in function or closure where return signature contain error type however it's not required when using withchannel
,casting
ormap
!
is not allow to use with channelRange
) and if initial statement.Syntax pattern:
var1, var2(?|!) := val1, val2 [=> error]
Compiler accepted
Compiler rejected
Thought
I've experimented with this syntax and my thought is, the syntax is short however it probably add a bit complexity to the compilation as the transformation or code generation must be done after a full type check is completed.
The text was updated successfully, but these errors were encountered: