4 ms·
Go actually has something akin to Sum types for errors, called wrapping. For example: var innerErr = errors.New("inner error") func innerFunc() er
by tail_exchange 3y ago
Go actually has something akin to Sum types for errors, called wrapping. For example:
var innerErr = errors.New("inner error")
func innerFunc() error {
return innerErr
}
func outerFunc() error {
err := innerFunc()
return fmt.Errorf("outer err: %w", err)
}
func main() {
err := outerFunc()
fmt.Println(errors.Is(err, innerErr)) // true
}
I don't think the Go community disagrees that it would be nice to make error handling a bit easier, because that was the top issue raised in the recent developer survey. The problem is that every proposal made so far either did not actually make error handling that much better, by looking at the feedback they received.