Skip to content

proposal: Go 2: Error-Handling Paradigm with !err Grammar Sugar #63647

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

Closed
xiaokentrl opened this issue Oct 20, 2023 · 3 comments
Closed

proposal: Go 2: Error-Handling Paradigm with !err Grammar Sugar #63647

xiaokentrl opened this issue Oct 20, 2023 · 3 comments
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 WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@xiaokentrl
Copy link

xiaokentrl commented Oct 20, 2023

Hi, if you like this idea please give a heart emoji to me, Thank you very much

package main
 
import (
    "fmt"
    "os"
)
 
func main() {
	/*
	func demo(){
	    file, err := os.Create("example.txt") 
	    if err != nil {
	        return nil, err
	    }
	    defer file.Close()
	}

       if  dd, err  := demo( ); err != nil {
            fmt.Printf( "dd" )
       }
	*/

	func demo_1(){
	    file := os.Create("example.txt").checkError( return , nil , err )     
	    defer file.Close()
            
           //   when【 .checkError( )   】 appears,auto append    file , err := os.Create("example.txt")
           //   when【 .checkError( return , nil , err )   】 appears,auto append  if err != nil 

	}
                          
	func demo_2(){
	    file := os.Create("example.txt").checkError( panic )
	    defer file.Close()
	}

	func demo_3(){
	    file := os.Create("example.txt").checkError( return , func(){
                return 2 + 3 , nil
            })
	    defer file.Close()
	}

	if dd := demo_1(); dd.hasError {         //  dd , err  := demo_1();  if err != nil
            fmt.Printf( "dd  hasError" )
            return
           //   when【 .hasError 】 appears,auto append    file , err := os.Create("example.txt")
           //   when【 .hasError 】appears,auto append  if err != nil 
	}
	fmt.Printf( "dd" )

}


or 

	func demo_1(){
	    file := os.Create("example.txt").checkError( return , nil , err )     // checkError( )  have "( )"
	    defer file.Close()
	}

        if dd := demo_1(); dd.checkError {    //checkError  not have "( )"

        }


or   


file := os.Create("example.txt").errReturn( return , nil , err ) 
// when【 .errReturn】 appears,  compiler auto append    " file , err := os.Create("example.txt")  "


       
@xiaokentrl xiaokentrl added LanguageChange Suggested changes to the Go language Proposal v2 An incompatible library change labels Oct 20, 2023
@gopherbot gopherbot added this to the Proposal milestone Oct 20, 2023
@xiaokentrl
Copy link
Author

xiaokentrl commented Oct 20, 2023

file := os.Create("example.txt").errReturn( nil , err )

if dd := demo( ); dd.hasErr {
    fmt.Printf( "has Error" )
}
file := os.Create("example.txt").err (  returnnil , err )

if dd := demo( ); dd.err ? {
    fmt.Printf( "has Error" )
}

@seankhliao
Copy link
Member

Please fill out https://github.com/golang/proposal/blob/master/go2-language-changes.md when proposing language changes

@seankhliao seankhliao added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Oct 21, 2023
@adonovan
Copy link
Member

adonovan commented Nov 1, 2023

This appears to be a duplicate of #63621. Please continue the discussion there.

@adonovan adonovan closed this as completed Nov 1, 2023
@seankhliao seankhliao added the error-handling Language & library change proposals that are about error handling. label Nov 17, 2023
@golang golang locked and limited conversation to collaborators Nov 16, 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 WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants