Tom Ritchford
Feb 18, 2023

--

This is pretty common in working code, though I don't work in Kotlin.

The classic example is an extended if, case, switch, or match statement that has a large number of branches (switches, cases, etc) which mostly return.

But if you don't return, then you throw an Exception, because you failed to perform a computation.

Another example is stubbing out methods you haven't written yet. You want the method to exist for type and variable checking, but it isn't ready - so you make the body a one-liner that throws an exception (`NotImplementedError` in Python).

Great article in general. If I were ever to go back to the Java ecosystem, it would be Kotlin or Clojure (or both :-D ).

--

--

No responses yet