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: spec: error != nil , add ? #57957

Closed
xiaokentrl opened this issue Jan 23, 2023 · 3 comments
Closed

proposal: spec: error != nil , add ? #57957

xiaokentrl opened this issue Jan 23, 2023 · 3 comments
Labels
error-handling Language & library change proposals that are about error handling. FrozenDueToAge Proposal v2 An incompatible library change
Milestone

Comments

@xiaokentrl
Copy link

xiaokentrl commented Jan 23, 2023

Author background

  • Would you consider yourself a novice, intermediate, or experienced Go programmer?
  • experienced
  • What other languages do you have experience with?
  • JAVA, PHP, C#, JS

Related proposals

  • Has this idea, or one like it, been proposed before?
    • YES
  • Does this affect error handling?
    • NO
  • Is this about generics?
    • NO

Problem
Most of the time in Go if an error occurs it can be returned. There are certain cases when this is not possible, usually go functions.

func f() (err os.Error) {
    v, err := g()
    if err != nil {
        return
    }
    if v {
        v, err := h()
        if err != nil {
            HandEorr()
        }
    }
}

Proposal

//Effect
func f() (err os.Error) {
    v, err := g() err? return
    if v {
        v, err := h() err? HandEorr()
    }
}


//Final Effect
func f() (err os.Error) {
    //if v, err := g() err? (return) {
    //if v, err := g() err return {    
    if v, err := g() err? (return) {
        v, err := h() err? HandEorr()
    }
}
//Hand Error

func main() {

    f, err := os.Open("/test.txt") err? {
       fmt.Println( err )
    }    
    
    f, err := os.Open("/test.txt") err? fmt.Println( err )
    f, err := os.Open("/test.txt") err? HandEorr( err )

    //or
    f, err := os.Open("/test.txt") err?
    fmt.Println( f )
}

? assert error

? assert  error

//or
? assert  False
//or
? assert  " "

// ---------------??------------------
?? assert  NaN         //  ? * 2
@gopherbot gopherbot added this to the Proposal milestone Jan 23, 2023
@xiaokentrl xiaokentrl changed the title proposal: Go 2: proposal: error != nil , add ? Jan 23, 2023
@xiaokentrl
Copy link
Author

xiaokentrl commented Jan 23, 2023

? assert error

? assert  error

//or
? assert  False
//or
? assert  " "

// ---------------??------------------
?? assert  NaN

@ianlancetaylor
Copy link
Contributor

Thanks. Similar proposals have been made before. See #40432.

@ianlancetaylor ianlancetaylor changed the title proposal: error != nil , add ? proposal: spec: error != nil , add ? Jan 23, 2023
@ianlancetaylor ianlancetaylor added v2 An incompatible library change error-handling Language & library change proposals that are about error handling. labels Jan 23, 2023
@seankhliao
Copy link
Member

Duplicate of #33074

@seankhliao seankhliao marked this as a duplicate of #33074 Jan 23, 2023
@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Jan 23, 2023
@golang golang locked and limited conversation to collaborators Jan 23, 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 Proposal v2 An incompatible library change
Projects
None yet
Development

No branches or pull requests

4 participants