Member-only story
Scala 3.1: Strict Exceptions And Faster Match
On 21/10/2022 the next subversion of Scala was released. The 3.1 version comes with a revolutionary strict exception feature.
Strict Exceptions In Scala
In Scala you can define what type a function will return:
The addInt function in the example above declares it will return an Int type value.
You can also throw errors in Scala:
In case divisor is a zero, division can not be executed thus throwing an Exception.
If you will compare these two examples, it is vivid that returning a value is strictly typed, while throwing error is not.
The compiler does not know what type of errors your function will throw. It is a dent in a strict typing paradigm.
With the Scala 3.1 release it changes with an experimental exception string typing: