Skip to content
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: errors handling #63380

Closed
saTechDev opened this issue Oct 4, 2023 · 1 comment
Closed

proposal: Go 2: errors handling #63380

saTechDev opened this issue Oct 4, 2023 · 1 comment
Labels
error-handling Language & library change proposals that are about error handling. FrozenDueToAge LanguageChange Suggested changes to the Go language Proposal v2 An incompatible library change
Milestone

Comments

@saTechDev
Copy link

Author background

  • An expert Go developer using it on daily basis
  • Excellent in C and good in Rust

Proposal

I think Go can add some syntax sugar that make the error handling easier. Developer can mark an error with a marker/operator and if this marked error is not 'nil' it's value will be returned.

Example

'''go
err! := example.ShouldRetErr()
'''

The '!' operator will simulates checking the err value and returning it if it's not 'nil' (maybe replace it with if statement behind-the-scenes) and we don't need to rewrite the if statement every time we get an error as a return.

The if statement errors handling still doable which guarantees backward compatibility.

@gopherbot gopherbot added this to the Proposal milestone Oct 4, 2023
@seankhliao seankhliao added LanguageChange Suggested changes to the Go language v2 An incompatible library change error-handling Language & library change proposals that are about error handling. labels Oct 4, 2023
@seankhliao
Copy link
Member

see #14066 #36390 #60779 #62253

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Oct 4, 2023
@golang golang locked and limited conversation to collaborators Oct 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
error-handling Language & library change proposals that are about error handling. FrozenDueToAge LanguageChange Suggested changes to the Go language Proposal v2 An incompatible library change
Projects
None yet
Development

No branches or pull requests

2 participants