2024-05-27 09:56:42 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
// New returns an error that formats as the given text.
|
|
|
|
|
// Each call to New returns a distinct error value even if the text is identical.
|
|
|
|
|
func New(text string) error {
|
|
|
|
|
return &errorString{text}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// errorString is a trivial implementation of error.
|
|
|
|
|
type errorString struct {
|
|
|
|
|
s string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (e *errorString) Error() string {
|
|
|
|
|
return e.s
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func main() {
|
2024-05-27 14:32:23 +08:00
|
|
|
println("main")
|
2024-05-27 09:56:42 +08:00
|
|
|
err := New("an error")
|
2024-05-27 14:32:23 +08:00
|
|
|
println("err")
|
2024-05-27 09:56:42 +08:00
|
|
|
println(err, err.Error())
|
|
|
|
|
}
|