Hacker News new | ask | show | jobs
by eadmund 427 days ago
> each of which must be changed when some library at the bottom of the stack changes slightly.

I hate checked exceptions too, but in fairness to them this specific problem can be handled by intermediate code throwing its own exceptions rather than allowing the lower-level ones to bubble up.

In Go (which uses error values instead) the pattern (if one doesn’t go all the way to defining a new error type) is typically to do:

    if err := doSomething(…); err != nil {
      return fmt.Errorf("couldn’t do something: %w", err)
    }
which returns a new error which wraps the original one (and can be unwrapped to get it).

A similar pattern could be used in languages with checked exceptions.