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: catch error model, a rethink of check/handle #68022

Closed
1 of 4 tasks
xiaokentrl opened this issue Jun 15, 2024 · 2 comments
Closed
1 of 4 tasks

proposal: Go 2: catch error model, a rethink of check/handle #68022

xiaokentrl opened this issue Jun 15, 2024 · 2 comments
Labels
error-handling Language & library change proposals that are about error handling. LanguageChange Suggested changes to the Go language Proposal v2 An incompatible library change

Comments

@xiaokentrl
Copy link

xiaokentrl commented Jun 15, 2024

Go Programming Experience

Intermediate

Other Languages Experience

JavaScript、PHP、C#、Delphi、JAVA

Related Idea

  • Has this idea, or one like it, been proposed before?
  • Does this affect error handling?
  • Is this about generics?
  • Is this change backward compatible? Breaking the Go 1 compatibility guarantee is a large cost and requires a large benefit

Has this idea, or one like it, been proposed before?

No.

Does this affect error handling?

No.

Is this about generics?

No.

Proposal

Err is object

file, err := os.Create("abc.txt")

//Err is object
Err.err      := err
Err.NotNill  := if err != nil
Err.Nill     := if err == nil

file := os.Create("abc.txt") ->Err.Nill.return(200,"ok")

//You can change lines.
file := os.Create("abc.txt")
	->Err.Nill.return(200,"ok")

file := os.Create("abc.txt") 
	->Err.Nill.callBack( funcName )

file := os.Create("abc.txt") 
	->Err.NotNill.callBack()


file := os.Create("abc.txt") ->Err.Has(1).callBack({
})

file := os.Create("abc.txt") ->Err.Value(1).In(1,2,3).callBack({
})

func main() {	
    file := os.Open("abc.txt") ->Eorr.Empty({
    defer file.Close()
    buf := make([]byte, 1024)
    _, err2 := file.Read(buf)
    return
})


//Multiline error handling
Err.ListenErr(
    file, err := os.Open("abc.txt")
    defer file.Close()

    buf := make([]byte, 1024)
    _, err := file.Read(buf)
){
    fmt.Printf("I don't want to deal with mistakes.\n")
    return "You can't know why it's wrong, because it's a secret."
}

Language Spec Changes

No response

Informal Change

No response

Is this change backward compatible?

Yes

Orthogonality: How does this change interact or overlap with existing features?

No response

Would this change make Go easier or harder to learn, and why?

No response

Cost Description

No response

Changes to Go ToolChain

No response

Performance Costs

No response

Prototype

No response

@xiaokentrl xiaokentrl added LanguageChange Suggested changes to the Go language Proposal v2 An incompatible library change labels Jun 15, 2024
@gabyhelp
Copy link

Similar Issues

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

@seankhliao seankhliao added the error-handling Language & library change proposals that are about error handling. label Jun 15, 2024
@seankhliao
Copy link
Member

I don't think we need a new proposal for every possible new syntax people can come up with. Realistically, proposals will have to be much more fleshed out to be considered.

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

No branches or pull requests

3 participants