Checked exceptions: Java’s biggest mistake (2014)
I&#x27;ve been using Scala quite heavily recently, having mostly used Haskell for years, with distant memories of Java. Scala allows Java methods to be called, but doesn&#x27;t bother with checked exceptions, which has bitten me quite a few times.<p>My preferred style of error-handling is Option&#x2F;Either, since I can implement the &#x27;happy path&#x27; in small, pure pieces; plug them together with &#x27;flatMap&#x27;, etc.; then do error handling at the top with a &#x27;fold&#x27; or &#x27;match&#x27;.<p>Exceptions break this approach; but it&#x27;s easy to wrap problematic calls in &#x27;Try&#x27; (where &#x27;Try[T]&#x27; is equivalent to &#x27;Either[Throwable, T]&#x27;).<p>The problem is that Scala doesn&#x27;t tell me when this is needed; it has to be gleaned from the documentation, reading the library source (if available), etc.<p>I get that a RuntimeException could happen at any point; but to me the benefit of checked exceptions isn&#x27;t to say &quot;here&#x27;s what you need to recover from&quot;, it&#x27;s to say &quot;these are very real possibilities you need to be aware of&quot;. In other words checked exceptions have the spirit of &#x27;Either[Err, T]&#x27;, but lack the polymorphism needed to make useful, generic plumbing. The article actually points this out, complaining that checked exceptions have to be handled&#x2F;declared through &#x27;all intervening code&#x27;; the same can actually be said of &#x27;Option&#x27;, or &#x27;Either&#x27;, or &#x27;Try&#x27;, etc., but the difference is that their &#x27;intervening code&#x27; is usually calculated by the higher-order functions provided by Functor, Applicative, Monad, Traverse, etc.<p>It&#x27;s similar to many developer&#x27;s first experience of Option&#x2F;Maybe: manually unwrapping them, processing the contents, wrapping up the result, then doing the same for the next step, and so on. It takes a while to grok that we can just map&#x2F;flatMap each of our steps on to the last (or use &#x27;for&#x2F;yield&#x27;, do-notation, etc. if available). It would be nice to have a similar degree of polymorphism for checked exceptions. Until then, I&#x27;d still rather have them checked (so I can convert them to a &#x27;Try&#x27;), rather than getting no assistance from the compiler at all!