im-a-baby
Joined 4 years ago
Joined 4 years ago
package main
import "fmt"
type MyError struct{}
func (m *MyError) Error() string {
return ""
}
func main() {
var err error = nil
var myErr *MyError = nil
fmt.Println(err == myErr) // this is false
} import "fmt"
type MyError struct{}
func (m *MyError) Error() string {
return ""
}
func myFunc() *MyError {
return nil
}
func main() {
var err error
err = myFunc()
if err == nil {
fmt.Println("No Error")
} else {
fmt.Println("Error") // This prints
}
}Similarly, you could prove a speaker doesn't eavesdrop by proving it performs a finite set of operations, none of which are eavesdropping.
Regarding the guard keyword, the author's proposal doesn't make sense. The guard call comes after the function call that produces the error, so it's not clear what is being guarded. I guess it's the error being wrapped in the guard message, but explaining that clearly in plain English is quite hard. I agree that context is important however. But maybe the Go team is finally ready to admit that stack traces are more useful than error messages. I'd be fine to know that, for example, an error occurred opening a file and having the language provide a full stack trace of where the error happened. I can do without the custom crafted error messages.