Indeed, the exception is a technical implementation detail and
Raise
itself can be considered pure in the type-system. Similar to how
Either
is pure, or rather referentially transparent.
We've experimented with a lot of different designs, and this is the only one that makes sense in Kotlin. TL;DR without exception you cannot interop with Kotlin Coroutines, and enforcing
suspend
poses
a lot of limitations in the API without any real benefits. AFAIK one of the reasons why Kotlin Coroutines choose
CancellationException
was to not break
try/finally
. Scala is also adding a similar construct into the language as
Raise
with the similar semantics, rationale and implementation called
Label
.