Member-only story
Keep using Java exceptions, when warranted
Every so often I come across an article with a headline saying you should never use this or that feature of a programming language. There is at least one such article for Java exceptions: stop using Java exceptions, never use them again.
Sometimes the body of the article gives a more nuanced pronouncement, like maybe only use exceptions to signal exceptional situations.
Other times the article gives some colossally goofy workaround to not use the feature you should supposedly never use. Either way, the article gets a lot more views than it would with a more measured headline.
We get the impression that the authors of such articles are trying to write something that’ll be as famous as Frank Rubin’s “Goto considered harmful.”
The problem with Goto in high level languages like BASIC and FORTRAN is that it obscures the program flow and logic with seemingly unmotivated jumps.
The computer doesn’t care about the reason for an unconditional jump, it just does it. So that information doesn’t appear in the compiled executable. But the program source we write is not just for the computer, it’s also for the other humans who might work with our program, and for ourselves.
With exceptions, the reasons for the jumps are quite clear. Consider this toy example: