@hongminhee@hollo.social

Unpopular opinion: Java's checked exceptions are underrated, and I think any language that uses exception-based error handling (rather than ADT-based error handling) should adopt checked exceptions.

4 replies

@mikebroberts@hachyderm.io · Reply to 洪 民憙 (Hong Minhee) :nonbinary:

@hongminhee From someone who first coded Java nearly 30 years ago (gulp) … I think the problem a lot of people had with checked exceptions back in the early 00s, at least, is that they were the default pattern. So it meant that what happened was everyone used them for all of their *internal* calls. Which led to basically every function call needing to define what to do with the exception and this added a lot of verbosity. Once we realized “oh, we can use RuntimeException” (unchecked) many of us switched to them. (It was not initially clear because the “Exception” type is checked, but “RuntimeException”, which extends “Exception”, is unchecked)

I think checked exceptions at the API boundary have value, but I’d still - personally - rather use Result types even if not explicit in the language. But I’ll admit that’s not standard practice.