Just when I think the Dotty project is completely settling down into staid boring bugfixes, a new experiment comes along.

Let’s note upfront: even more than usual, this is super-duper experimental — just a draft PR, far from merged, much less being seriously discussed for inclusion in Scala 3. I suspect that, at the earliest, we might wind up talking about something like this in stdlib for 3.1.

That said, check out this fascinating PR from Martin. It is basically kicking the tires with a way that you could implement typesafe checked Exceptions in Scala, with no runtime overhead, with only a little new compiler support beyond stuff that’s already in.

The most interesting bit is the tests, of which there are a bunch, demonstrating how you could, using standard language machinery, define an erased given CanThrow type and an infix throws type, allowing you to say things like

def bar: Int throws Exception =

The idea of checked Exceptions is a bit controversial, given its history in Java, but this is pretty neat to see, not least as an illustration of how much power you can derive from the tools already in the language, without having to bake everything into the compiler.

I commend it as worth a read, for educational purposes if nothing else — it’s a great demonstration of the power of the new erased keyword, and the notion of capabilities that is starting to emerge.

Lifelong programmer and software architect, specializing in online social tools and (nowadays) Scala. Architect of Querki (“leading the small data revolution”).

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store