Go Programming Experience

Intermediate

Other Languages Experience

JavaScript、PHP、C#、Delphi、JAVA

Related Idea

  • [ ] Has this idea, or one like it, been proposed before?
  • [X] 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

Comment From: gabyhelp

Similar Issues

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

Comment From: seankhliao

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.