-
Notifications
You must be signed in to change notification settings - Fork 18.3k
Closed
Labels
FrozenDueToAgeLanguageChangeSuggested changes to the Go languageSuggested changes to the Go languageProposalerror-handlingLanguage & library change proposals that are about error handling.Language & library change proposals that are about error handling.v2An incompatible library changeAn incompatible library change
Milestone
Description
I had an Epiphany last night like this:
func readAllText(path string) string {
buffer, err := ioutil.ReadFile(path)
if err != nil {
goto handler
}
return string(buffer)
handler:
{
fmt.Println("error: ", err.Error())
return ""
}
}
Only the second value is detected each time, and if more than one value is returned, it is recommended to encapsulate it as a type,
If you provide a keyword to detect whether the second variable is nil like this:
a,err := method()
check err goto handler
b,err := method2()
if err != nil{
// Special error handling...
}
handler:
{
fmt.Println("error: ", err.Error())
}
This makes it compatible with previous or future error handling,Can you solve the problem of error handling
Finally , I'm sorry for my poor English
Metadata
Metadata
Assignees
Labels
FrozenDueToAgeLanguageChangeSuggested changes to the Go languageSuggested changes to the Go languageProposalerror-handlingLanguage & library change proposals that are about error handling.Language & library change proposals that are about error handling.v2An incompatible library changeAn incompatible library change