You have a function that either returns a value or throws an exception.
Change the function's return type to a disjunction of the original return type and the exception.
We use the following form for our disjunction, called
This is similar to Scala's built-in
Either type, but with support for
Checked exceptions force the developer to wrap their code in
try/catch blocks, yielding noisy code that's hard to reason about, hard to combine, and impure in languages where
try/catch blocks are not expressions.
Unchecked exceptions allow the developer to forget to wrap their code in
try/catch blocks, creating a runtime timebomb.
When encountering an expression that throws an exception, note the types of the exception that it can throw, and the value that it can return. We'll call these
Remodel the expression's return type to
throw e into
Change any return
quotient: -999 quotientE: Left(java.lang.ArithmeticException: / by zero) quotientE2: Left(java.lang.ArithmeticException: / by zero)