proposal: Go 2: error handling with handle keyword and optional return of error type #54677
Labels
error-handling
Language & library change proposals that are about error handling.
FrozenDueToAge
LanguageChange
Suggested changes to the Go language
Proposal
Proposal-FinalCommentPeriod
v2
An incompatible library change
Milestone
Would you consider yourself a novice, intermediate, or experienced Go programmer? - intermediate.
What other languages do you have experience with? - rust/haskell/c/ruby.
Would this change make Go easier or harder to learn, and why? - no effect.
Has this idea, or one like it, been proposed before? - can't say.
Who does this proposal help, and why? - possibly it will help everyone, because it will make whole error handling more convenient.
Is the goal of this change a performance improvement? - no
Does this affect error handling? - yes. Key differences: backward compatible, (kinda) looks like other parts of the go, no new types, function signatures the same.
What is the proposed change?
Please also describe the change informally, as in a class teaching Go.
Basically, there will be easier way of error handling with new keyword handle, that checks if function returns error and if there is no handle body, it will just return error or exit function with default values for other return parameters. Additionally, returning nil value for error will be optional.
Is this changes backward compatible?
Yes, because nothing there will change function signatures, or anything else that can break backward compatibility.
Example
before
after
Affected tools
Other pros
The text was updated successfully, but these errors were encountered: