site icon indicating copy to clipboard operation
site copied to clipboard

Article: Why throwing errors isn't type-safe

Open JoshuaKGoldberg opened this issue 1 year ago • 0 comments

Overview

Speaking generally: https://softwareengineering.stackexchange.com/questions/189222/are-exceptions-as-control-flow-considered-a-serious-antipattern-if-so-why is a good summary of my perspective here.

I think the most salient point is the Principle of Least Astonishment. Since exceptions can't reasonably be indicated in type signatures, using exceptions requires developers memorizing which functions may throw them as a part of their "normal" flow. That's a recipe for astonishment - especially if the implicit intentional-exception-throwing contract changes unexpectedly.

JoshuaKGoldberg avatar Feb 12 '24 12:02 JoshuaKGoldberg