Can we create subtypes for errors in Go?
问题 I want to create hierarchical errors in Go. Can we achieve this in Go ? For an example, I have following two errors. type Error1 struct { reason string cause error } func (error1 Error1) Error() string { if error1.cause == nil || error1.cause.Error() == "" { return fmt.Sprintf("[ERROR]: %s\n", error1.reason) } else { return fmt.Sprintf("[ERROR]: %s\nCaused By: %s\n", error1.reason, error1.cause) } } type Error2 struct { reason string cause error } func (error2 Error2) Error() string { if