Hacker News new | ask | show | jobs
by mquander 5518 days ago
Well, it's an awkward solution, because exceptions have this general problem of blowing away everything you're doing, and it's only a solution for this one case.

The solution to this problem that makes sense to me is either conditions and restarts a la Common Lisp, or a type system that can handle multiple return values of different types in a sane way (e.g. return either a result or an error code and then pattern match against them) so that you don't always need to throw an exception in order to deal with an error.

1 comments

Exceptions are little more than a formalization of a particular pattern of what Haskell might call the Either monad for return values, combined with pattern matching on the error type, and automatic unwinding. A condition system has positive value; but multiple return types with error codes alongside, like Go, are a regression from exceptions, IMO.